NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code
https://hardhat.org
MIT License
174 stars 44 forks source link

Range exceptioning on bad inputs #150

Open sentry-io[bot] opened 2 years ago

sentry-io[bot] commented 2 years ago

Sentry Issue: VSCODE-EXTENSION-1QN

Error: Range#create called with invalid arguments[[object Object], [object Object], undefined, undefined]
  File "/Users/pvu/.vscode/extensions/nomicfoundation.hardhat-solidity-0.2.0/server/out/index.js", line 31, in Object.Ki [as create]
    '{snip} s,Ri)};if(s.is(mi)&&s.is(Nn))return{start:mi,end:Nn};throw new Error("Range#create called with invalid arguments["+mi+", "+Nn+", "+gs+", "+R {snip}
  File "/Users/pvu/.vscode/extensions/nomicfoundation.hardhat-solidity-0.2.0/server/out/index.js", line 1722, in Mre
    '{snip} .character-r.length};return j20.TextEdit.replace(j20.Range.create(a,n),x)}function Mwx(x,n,r){let{rootPath:a,documentsAnalyzer:s}=r;return a {snip}
  File "/Users/pvu/.vscode/extensions/nomicfoundation.hardhat-solidity-0.2.0/server/out/index.js", line 1722, in <anonymous>
    '{snip} Analyzer:s})).map(f=>{let d=Vwx(f);return{label:d,textEdit:Mre(d,x,n),kind:M1.CompletionItemKind.Module,documentation:"Imports the package"} {snip}
  File "/Users/pvu/.vscode/extensions/nomicfoundation.hardhat-solidity-0.2.0/server/out/index.js", line 1722, in Mwx
    '{snip} mentsAnalyzer:s},n):jre({rootPath:a,documentsAnalyzer:s})).map(f=>{let d=Vwx(f);return{label:d,textEdit:Mre(d,x,n),kind:M1.CompletionItemKin {snip}
  File "/Users/pvu/.vscode/extensions/nomicfoundation.hardhat-solidity-0.2.0/server/out/index.js", line 1722, in Rre
    '{snip} wx(r);return f.concat(d)}else return Bwx(s)?Bre(x,s,u,n,a):Mwx(x,s,r)}function Bwx(x){return x.startsWith(".")}function Bre(x,n,r,a,s){if(/[ {snip}
...
(5 additional frame(s) were not displayed)

We are doing a range conversion that is throwing on bad inputs.

github-actions[bot] commented 2 years ago

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: 6ff8371d-d1a0-4b34-82bf-bde8708d28be

kanej commented 1 year ago

We are still seeing this in the sentry logs.

@OmarTawfik raised the point this may be related to some errors returned from solc not having source locations (i.e. error.sourceLocation). If that is the case we should deal errors of this sort as their own case, and eliminate the source of the bad inputs.

OmarTawfik commented 1 year ago

I have a suspicion it is related to checks like these:

https://github.com/NomicFoundation/hardhat-vscode/blob/9cfb24bb204bdab9b6f58f7598467205cc401887/server/src/services/validation/DiagnosticConverter.ts#L76-L82

https://github.com/NomicFoundation/hardhat-vscode/blob/9cfb24bb204bdab9b6f58f7598467205cc401887/server/src/compilerDiagnostics/conversions/constrainByRegex.ts#L10-L12

I wonder if we should treat such locations as [0,0] instead of throwing/failing? Looks to me like it will still be an improvement to the end-user experience.

antico5 commented 1 year ago

@kanej This error is from 0.5.4 and earlier. Since then I've changed the import path completions logic and we don't have occurrences of this error on newer versions. Should I close the issue ?

kanej commented 1 year ago

@kanej This error is from 0.5.4 and earlier. Since then I've changed the import path completions logic and we don't have occurrences of this error on newer versions. Should I close the issue ?

Sentry is confusing on these sorts of thing. It doesn't necessarily merge new instances with the old version.

The Range#create exception is still happening: https://nomic-labs.sentry.io/issues/3758407495/?project=5469451&query=is%3Aunresolved+create&referrer=issue-stream&statsPeriod=14d&stream_index=0