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

raw.name! is undefined in debug-source.ts #15096

Open
BrightKn1ght opened this issue Mar 3, 2025 · 0 comments
Open

raw.name! is undefined in debug-source.ts #15096

BrightKn1ght opened this issue Mar 3, 2025 · 0 comments

Comments

@BrightKn1ght
Copy link

I have quite complex remote debug behavior of a python script using debugpy and Theia 1.55.1.

Bug Description:

When I launch the debugging an exceptions occurs at:

logger-protocol.js:97 2025-03-03T08:41:11.187Z root ERROR fetchFrames failed: TypeError: Cannot read properties of undefined (reading 'toString')
    at r.withPath (https://localhost:8443/ide/bundle.js:2:8399171)
    at a.toUri (https://localhost:8443/ide/bundle.js:2:3186482)
    at s.getSource (https://localhost:8443/ide/bundle.js:2:7810185)
    at t.DebugStackFrame.update (https://localhost:8443/ide/bundle.js:2:9996831)
    at t.DebugThread.doUpdateFrames (https://localhost:8443/ide/bundle.js:2:6856289)
    at https://localhost:8443/ide/bundle.js:2:6855626

It turns out that in debug-source.ts at line 83 the raw.name! is undefined:

static toUri(raw: DebugProtocol.Source): URI {
        if (raw.sourceReference && raw.sourceReference > 0) {
            return new URI().withScheme(DEBUG_SCHEME).withPath(raw.name!).withQuery(String(raw.sourceReference)); // <-- Usage of name without check
        }
        if (!raw.path) {
            throw new Error('Unrecognized source type: ' + JSON.stringify(raw));
        }
        if (raw.path.match(SCHEME_PATTERN)) {
            return new URI(raw.path);
        }
        return new URI(Uri.file(raw.path));
    }

Does someone know how this could happen?

Steps to Reproduce:

  1. I think my setup is too complex to reproduce.

What I found out from looking at debugpy logs, is that debugpy is kind of creating translations for file paths:

0.00s - sending cmd (http_json) -->           CMD_RETURN {"type": "response", "request_seq": 14, "success": true, "command": "threads", "body": {"threads": [{"id": 1, "name": "MainThread"}]}, "seq": 36, "pydevd_cmd_id": 502}

0.00s - Process StackTraceRequest: {
    "arguments": {
        "format": {},
        "levels": 1,
        "startFrame": 0,
        "threadId": 1
    },
    "command": "stackTrace",
    "seq": 15,
    "type": "request"
}

0.00s - Created source reference: 1 for untranslated path: /var/snap/rexroth-automationcore/common/solutions/activeConfiguration/scripts/bosch/tiger/16uhr--d34d2e4d-c5d6-41b6-9f1b-82156db6b20d.py
0.00s - sending cmd (http_json) -->     CMD_MODULE_EVENT {"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": 0, "name": "__main__", "path": "/var/snap/rexroth-automationcore/common/solutions/activeConfiguration/scripts/bosch/tiger/16uhr--d34d2e4d-c5d6-41b6-9f1b-82156db6b20d.py", "package": "None"}}, "seq": 38, "pydevd_cmd_id": 203}

0.00s - Created source reference: 2 for untranslated path: <string>
0.00s - sending cmd (http_json) -->     CMD_MODULE_EVENT {"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": 1, "name": "__main__", "path": "<string>", "package": "None"}}, "seq": 40, "pydevd_cmd_id": 203}

0.00s - sending cmd (http_json) -->           CMD_RETURN {"type": "response", "request_seq": 15, "success": true, "command": "stackTrace", "body": {"stackFrames": [{"id": 2, "name": "<module>", "line": 27, "column": 1, "source": {"path": "/var/snap/rexroth-automationcore/common/solutions/activeConfiguration/scripts/bosch/tiger/16uhr--d34d2e4d-c5d6-41b6-9f1b-82156db6b20d.py", "sourceReference": 1}}], "totalFrames": 2}, "seq": 42, "pydevd_cmd_id": 502}

And when theia finds info about sourceReference in debug-source.ts it tries to build the URL from that:
return new URI().withScheme(DEBUG_SCHEME).withPath(raw.name!).withQuery(String(raw.sourceReference));

Additional Information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant