Comments (6)
Some slight changes to what I noted above, with the latest change errors in analysis_options
/pubspec
are prioritized and shown first with an additional message:
Analyzing myapp...
Errors were found in 'pubspec.yaml' and/or 'analysis_options.yaml' which might result in either invalid diagnostics being produced or valid diagnostics being missed.
error • analysis_options.yaml:3:1 • Expected ':'. • parse_error
Errors in remaining files.
error • lib\main.dart:1:16 • A value of type 'Null' can't be returned from the function 'foo' because it has a return type of 'int'. • return_of_invalid_type
2 issues found.
from sdk.
Should probably catch the error and report it (more) gracefully. Don't know if this should be handled in the dart
executable or at the analyzer end, but printing null
suggests it's the CLI end that doesn't handle server errors.
(If the YAML parser could be made to recover from errors, it might be possible to give more precise errors too, but that depends on the yaml
package.)
from sdk.
\cc @DanTup Since I think you recently added some handling for when the analysis server crashes.
from sdk.
I think there are two behaviours here that may be questionable, but I don't know what the desired behaviour is for each (cc @bwilkerson).
-
What should the server do with an invalid analysis_options? Currently it's throwing an unhandled exception while trying to set the analysis which is sent back to the client with a stack trace. This seems wrong to me, but I don't know if the error is considered fatal or not.. If so, it should probably report the error in a more friendly way, and if not, should it just continue to set up the analysis roots and analyze as if the invalid file (or parts of) didn't exist?
-
If the server does return an unhandled error to
dart analyze
, how should it be presented? The original comment above suggests it should be more user friendly (presumably not be a raw exception/stack trace) but if this is an edge case and indicates a bug in the server, I wonder if this information is useful, because it results in a much better bug report than if it was not included. I think this might depend on the kind of exception.. For example the above code isOptionsFormatException
which suggests we know the issue here is an invalidanalysis_options.yaml
and could provide a useful message without the full exception. But if it was something like aRangeError
, I think the raw exception could be useful (in which case, maybedart analyze
s behaviour is fine here, and the server should handle exactly what's in the server error responses).
from sdk.
What should the server do with an invalid analysis_options? Currently it's throwing an unhandled exception while trying to set the analysis which is sent back to the client with a stack trace. This seems wrong to me ...
I agree. I don't think the server should be returning an exception in this case.
The general design of the server is to recover from errors as cleanly as possible, notifying the user of the error with enough information that the user can fix the problem.
I don't know what the limitations of the yaml
package are in this case, but server should, to the best of its ability, create a diagnostic indicating the location and nature of the problem. If it gets back a partial view of the file then we ought to use as much of the file as we get and ignore the rest, and then proceed with analysis.
Ideally, the dart analyze
tool would then look at the diagnostics that are returned, and, if there are diagnostics reported against either any analysis_options.yaml
or pubspec.yaml
files it should print
- a notice indicating that the rest of the analysis might not be correct because of those issues,
- the diagnostics that might invalidate the rest of the results,
- a header indicating that the questionable diagnostics follow
- the rest of the diagnostics (or notice that no other diagnostics were found if that's the case).
If the server does return an unhandled error to
dart analyze
, how should it be presented?
Given that this should only happen as a result of an internal bug that the server couldn't recover from, I think it's reasonable for the command-line tool to print out the message and stack trace, prefixed by a message explaining that this is an internal error and asking the user to report it.
from sdk.
It seems we already handle generating diagnostics for the case above, the issue is just that the server crashes before it gets there (during setting the roots). There are many places already handling these errors, but not path in the stack trace above.
I've started a change at https://dart-review.googlesource.com/c/sdk/+/371861 which:
- Changes the text for unhandled errors from
Error from the analysis server: (error)
to
An unexpected error was encountered by the Analysis Server.
Please file an issue at https://github.com/dart-lang/sdk/issues/new with the following details:
(this text was copied from another place indartdev
that handles top=level errors) - Handles the parse error by returning an empty map for the options (as other places already did)
- Adds a suffix to analysis_options parse errors:
Parse errors in analysis_options.yaml may result in other incorrect diagnostics.
The result is that dart analyze
with the above analysis_options.yaml looks like this:
I'm not sure if we want to just mash that text on to the end of the error like that though - it's not what was suggested above, but it does mean that it appears in the clients instead of only dart analyze
(where the same problem exists). We can discuss this on the CL though.
from sdk.
Related Issues (20)
- `String.fromCharCode[s]` should be deprecated and renamed to `String.fromRune[s]` HOT 4
- "Error: The macro can only be applied to enums or enum values." - What interface to use instead? HOT 1
- Failures on [ CLI ] Fix issue where 'dart build' would fail to find the 'dart' when run from PATH
- Analyzer response to LSP requests extremely slow w/ high latency reported HOT 19
- [breaking change] On Windows refer to special `null` file as '\\?\nul' rather than 'nul'. HOT 7
- LSP Server fails to initialize if an inlayHints request is sent before the client responds to workspace/configuration HOT 24
- DateTime implementation on linux, dates before year 2020 return incorrect timezone HOT 8
- Inconsistent behavior of beginToken for some analyzer AST nodes with doc comments HOT 1
- [dart2js] Incorrect inference for override with default of widened type
- [ddc] Incorrect defaulting of named arguments with certain names
- DDC async function stepping improvements HOT 1
- When performing floating-point calculations, precision may be lost在进行浮点数计算时精度会丢失 HOT 7
- [typed_data] Add `Float16List` + [vm/ffi] Add `Float16` HOT 15
- Code completion contains many duplicated items (for extensions?)
- dart2wasm miscompilation around dynamic switch targets HOT 2
- Unexpected TypeError from js_interop only in DDC HOT 1
- Maybe ZoneSpecification's fork behavior is broken? HOT 3
- Attempt to start the daemon using the IPv6 loopback if the machine does not have 127.0.0.1 loopback IP address
- [ddc] Can we migrate all calls of `getReifiedType()` to a member of the dart:rti library?
- Analyzer Feedback from IntelliJAnalysis server has terminated HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.