rokucommunity / vscode-brightscript-language

A Visual Studio Code extension for Roku's BrightScript language
MIT License
104 stars 41 forks source link

Decode roku error codes #94

Open TwitchBronBron opened 5 years ago

TwitchBronBron commented 5 years ago

When encountering an error on a remote Roku device, sometimes the errors contain codes like &h02. We should decode those errors to provide more benefit to end users. Here's a forum post listing what many of those error codes are:

https://forums.roku.com/viewtopic.php?t=33193#p211138

I envision we would scan all roku output (or at least the error output) and replace things like &h02 with &h02 (ERR_SYNTAX).

This might be better implemented in roku-debug, but leaving the issue here for now until we work out the details.

philanderson888 commented 1 year ago

Picking this up for inspection ...

philanderson888 commented 1 year ago

14/2/2023 Meeting with @TwitchBronBron to discuss details - going to go through recorded video now ...

philanderson888 commented 1 year ago

To do - check with Roku (Ben?) if and updated version exists ... https://forums.roku.com/viewtopic.php?t=33193#p211138

philanderson888 commented 1 year ago

Have launch flag with default is to enhance the hex codes, can be disabled.

Investigation ... possibly turn codes into a hyperlink .... at log presentation layer ...

start point is https://github.com/rokucommunity/vscode-brightscript-language/blob/master/src/LogOutputManager.ts

suggestion is to output as

&h08 (ERR_FC: ... detail of message here)

philanderson888 commented 1 year ago

Just installing all the libraries and packages and dependencies from a clean install ...

philanderson888 commented 1 year ago

Impressed with the folder icons, nice touch

image

philanderson888 commented 1 year ago

Just in the setup last week I can get the main VSCode extension set up but when I hit 'Run and Debug' button for Extension (vscode-brightscript-language) I am getting

 *  Executing task in folder ⚡vscode-brightscript-language: npm run watch-all --loglevel silent 

 *  The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command npm run watch-all --loglevel silent" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder ⚡vscode-brightscript-language: npm run watch-webviews 

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\github/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\github\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\phila\AppData\Local\npm-cache\_logs\2023-02-26T12_06_02_147Z-debug-0.log

 *  The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command npm run watch-webviews" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

however when I run the commands separately and individually in my own separate powershell they both work fine

PS C:\github\RokuCommunity\vscode-brightscript-language> npm run watch-all --loglevel silent

12:10:54 PM Starting compilation in watch mode...
✔ brighterscript, ✔ roku-deploy, ✔ roku-debug, ✔ brighterscript-formatter, ✔ vscode-brightscript-language

[12:11:06 PM] Found 0 errors. Watching for file changes.

and

PS C:\github\RokuCommunity\vscode-brightscript-language> npm run watch-webviews

> brightscript@2.38.8 watch-webviews
> cd ./webviews && npm run watch

> webviews@0.0.0 watch
> vite build --watch

vite v4.0.0 building for production...

watching for file changes...

build started...
✓ 468 modules transformed.
12:11:45 [vite-plugin-svelte] dom compile done.
package         files    time     avg
webviews          438   1.55s   3.5ms
../dist/webviews/index.html                   0.47 kB
../dist/webviews/assets/index-b964633f.css    7.38 kB │ gzip:  1.98 kB
../dist/webviews/assets/index-d47255ce.js   533.62 kB │ gzip: 89.91 kB
built in 3542ms.

seems odd. the command is somehow not seeing the package.json at the right level, but is trying to find it from root ie we are getting

 *  Executing task in folder ⚡vscode-brightscript-language: npm run watch-webviews 

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\github/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\github\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\phila\AppData\Local\npm-cache\_logs\2023-02-26T12_06_02_147Z-debug-0.log
TwitchBronBron commented 1 year ago

That's strange. Can you change your default shell to something else and try it again? like cmd or "git bash" (that's what I use)? image

Alternatively, try deleting the RokuCommunity folder (and all the subfolders), and then run the setup scripts again. perhaps something got corrupted?

philanderson888 commented 1 year ago

Aha ! Thank you for this simple fix ... I can get on with the work now @TwitchBronBron cheers :)

image

philanderson888 commented 1 year ago

@TwitchBronBron

First instance try running this code

        if (isLogOutputEvent(e)) {

            const errorCodes = new Map<string, string>([
                ['&hFF', '(ERR_OKAY:)'],
                ['&hFC', '(ERR_NORMAL_END: normal, but terminate execution.  END, shell "exit", window closed, etc'],
                ['&hE2', '(ERR_VALUE_RETURN: return executed, and a value returned on the stack)']
            ]);

            // need to upgrade this includes statement to include a full hex regex
            if (e.body.line.includes('&h')) {
                this.appendLine('its a match with &h');
                const regexGlobal = /&h[0-9A-F][0-9A-F]/g;
                const regexMatches = e.body.line.match(regexGlobal);
                for (const regexMatch of regexMatches) {
                    this.appendLine('regex item found ' + regexMatch);
                    if (errorCodes.has(regexMatch)) {
                        const errorDescription = errorCodes.get(regexMatch);
                        e.body.line = e.body.line.replace(regexMatch, regexMatch + ' ' + errorDescription + ' ');
                    }
                }
            }
            this.appendLine(e.body.line);

        } else if (isPopupMessageEvent(e)) {
            this.showMessage(e.body.message, e.body.severity);

with print lines

    print "error 1 &hFF "
    print "error 2 &hFC"
    print "error 3 &hE2"
    print "error 4 &hCC this one is not matched"

produces output Window

its a match with &h
finding 1 matches
regex item found &hFF
error 1 &hFF (ERR_OKAY:)  

its a match with &h
finding 1 matches
regex item found &hFC
error 2 &hFC (ERR_NORMAL_END: normal, but terminate execution.  END, shell "exit", window closed, etc 

its a match with &h
finding 1 matches
regex item found &hE2
error 3 &hE2 (ERR_VALUE_RETURN: return executed, and a value returned on the stack) 

its a match with &h
finding 1 matches
regex item found &hCC
error 4 &hCC this one is not matched

although debug console output is unaffected

error 1 &hFF 
error 2 &hFC
error 3 &hE2
error 4 &hCC this one is not matched
philanderson888 commented 1 year ago

https://github.com/rokucommunity/vscode-brightscript-language/pull/467

draft pull request

@TwitchBronBron thanks