Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor error message when names conflict #32231

Closed
OliverJAsh opened this issue Jul 3, 2019 · 9 comments · Fixed by #52740
Closed

Poor error message when names conflict #32231

OliverJAsh opened this issue Jul 3, 2019 · 9 comments · Fixed by #52740
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Milestone

Comments

@OliverJAsh
Copy link
Contributor

TypeScript Version: 3.5.2

Search Terms: debug failure unexpected node error message exception

Obviously the following code is incorrect, however I would expect a friendly error message directing the user to the problem, rather than the nasty/ambiguous error message that is currently given: Error: Debug Failure. Unexpected node.

I ran into this in a large codebase and it took me awhile to find source of the problem.

Code

yarn add @types/lodash
import * as pick from 'lodash/pick';

export const pick = () => pick();
$ tsc

/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:73748
                throw e;
                ^

Error: Debug Failure. Unexpected node.
Node 156 was unexpected.
    at getDeclarationSpaces (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46074:41)
    at /Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46066:84
    at Object.forEach (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:217:30)
    at getDeclarationSpaces (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46066:28)
    at checkExportsOnMergedDeclarations (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46009:41)
    at checkVariableLikeDeclaration (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:47011:17)
    at checkVariableDeclaration (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:47048:20)
    at checkSourceElementWorker (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:48787:28)
    at checkSourceElement (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:48648:17)
    at Object.forEach (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:217:30)
@fatcerberus
Copy link

Error: Debug Failure. Unexpected node

🐞
That's not a normal error message. The compiler actually crashed. It's 100% a bug. 😄

@sandersn sandersn added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Jul 9, 2019
@sandersn
Copy link
Member

sandersn commented Jul 9, 2019

What version of lodash is this?

@sandersn
Copy link
Member

sandersn commented Jul 9, 2019

repros with @types/lodash@4.14.136. The unexpected node kind is MethodSignature, which probably has something to do with following an alias along until the original pick method is encountered.

@sandersn sandersn added this to the Backlog milestone Jul 9, 2019
@sandersn
Copy link
Member

sandersn commented Jul 9, 2019

Starting failing this way in 2.6.

@captain-yossarian
Copy link

I have same error:
ERROR in [internal] INTERNAL ERROR: Debug Failure. Unexpected node. Node Identifier was unexpected. stack trace: Error: Debug Failure. Unexpected node. Node Identifier was unexpected. at getDeclarationSpaces (app\node_modules\type script\lib\typescript.js:59394:41) at checkExportsOnMergedDeclarations (app\node_ modules\typescript\lib\typescript.js:59320:41) at checkVariableLikeDeclaration (app\node_modu les\typescript\lib\typescript.js:60568:17) at checkVariableDeclaration (app\node_modules\ typescript\lib\typescript.js:60606:20) at checkSourceElementWorker (app\node_modules\ typescript\lib\typescript.js:63058:28) at checkSourceElement (app\node_modules\typesc ript\lib\typescript.js:62912:17) at Object.forEach (app\node_modules\typescript \lib\typescript.js:309:30) at checkVariableStatement (app\node_modules\ty pescript\lib\typescript.js:60616:16) at checkSourceElementWorker (app\node_modules\ typescript\lib\typescript.js:63027:28) at checkSourceElement (app\node_modules\typesc ript\lib\typescript.js:62912:17)

after migration from 3.5.3 to 3.7.4.
And I have no clue which package triggers this error, because project is big

@captain-yossarian
Copy link

captain-yossarian commented Jan 17, 2020

@sandersn I think I've figured out why this error happens, at least in my code.
My code:

/**
 * @typedef (Object) CustomProps
 * @property (Boolean) visible
 * @property (children:React.ReactNode) children
 *
 * @param {CustomProps} props
 */
const SomeComponent=(props)=><div>Hello</div>;

As you see, there is invalid JSDoc syntax.
TS compiler crashed here typescript\lib\typescript.js:59394.

// d.kind = 75, SyntaxKind.Identifier
return ts.Debug.failBadSyntaxKind(d)

After JSDoc code was fixed, the error is gone.
I hope it will help.

@joeprivettsmart
Copy link

I'm getting a similar error, though not speicific to lodash:

/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70731
                    return ts.Debug.failBadSyntaxKind(node);
                                    ^
Error: Debug Failure. Unexpected node.
Node 193 was unexpected.
    at serializeTypeNode (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70731:37)
    at serializeTypeOfNode (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70594:28)
    at addOldTypeMetadata (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70536:97)
    at addTypeMetadata (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70530:17)
    at transformAllDecoratorsOfDeclaration (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70447:13)
    at generateClassElementDecorationExpression (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70472:40)
    at generateClassElementDecorationExpressions (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70458:34)
    at addClassElementDecorationStatements (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70451:44)
    at visitClassDeclaration (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70252:13)
    at visitTypeScript (/Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js:70137:28)

How do I even start to debug this?

@sandersn
Copy link
Member

sandersn commented Feb 6, 2023

@joeprivettsmart If you can get this caught in the debugger, you can probably find a SourceFile object somewhere in the stack and inspect its name.

Basically, node --inspect-brk /Users/joe.privett/Sources/cms/node_modules/typescript/lib/tsc.js, then put a breakpoint in serializeTypeNode on the ts.Debug.failBadSyntaxKind.

The alternative is "binary debugging", in which you delete half of your files at a time to see which ones had the bad node.

Either way, I'm pretty sure it's in a file with decorators because that's serializeTypeNode says that it converts type nodes to their equivalent runtime types.

It would be a good idea to open a new bug while you're at it, because your stack is quite different from the original one.

@Andarist
Copy link
Contributor

The test case for the original issue reported by @OliverJAsh here:

// @strict: true
// @noEmit: true

// @filename: node_modules/@types/lodash/object.d.ts
import _ = require("./index");
declare module "./index" {
    interface LoDashStatic {
      pick<T extends object, U extends keyof T>(
        object: T,
        ...props: Array<U>
      ): Pick<T, U>;
    }
}

// @filename: node_modules/@types/lodash/pick.d.ts
import { pick } from "./index";
export = pick;

// @filename: node_modules/@types/lodash/index.d.ts

/// <reference path="./object.d.ts" />
export = _;
export as namespace _;
declare const _: _.LoDashStatic;
declare namespace _ {
    interface LoDashStatic {}
}

// @filename: index.ts
import * as pick from 'lodash/pick';
export const pick = () => pick();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants