icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Better error message for Slice2 enum without underlying type #569

Closed pepone closed 1 year ago

pepone commented 1 year ago

If you forget to add define the underlying type for an Slice2 enum you get an error like:

Severity    Code    Description Project File    Line    Suppression State
Error   E011    invalid enum 'ObsoleteEnum': underlying type 'None' is not supported for enums  IceRpc.Tests    C:\Users\jose\source\repos\icerpc-csharp\tests\IceRpc.Tests\Slice\ProxyTests.slice  38  

I think it would be clear to have a custom message here telling the underlying type is required

bernardnormier commented 1 year ago

I see also a number of other issues with this message:

Cleaned-up version

error E011: invalid enum 'MyEnum': underlying type 'None' is not supported for enums
error E011: file is using the Slice2 encoding by default
error E011: to use a different encoding, specify it at the top of the slice file
error E011: ex: 'encoding = Slice1' 
error E011: try adding a backing type to your enum: 'enum MyEnum: varint32'
  1. We should not use "ex:" to mean "for example"
  2. We should use a consistent terminology for underlying types: not underlying on one line and backing on the next
  3. We should use the correct formatting in message (see #573)
  4. I would suggest uint8 as the underlying type: 99.9% of the time, that's what you want

And the main gist of the message seems to be "are you sure you didn't mean to add encoding = Slice1?", which I find misleading.

As Jose pointed out, I think it makes more sense to focus on the missing underlying type and not Slice encoding of the file.

externl commented 1 year ago

How about this @pepone @bernardnormier :


error [E011]: invalid enum 'Bar': underlying type 'None' is not supported for enums
 --> foo.slice:3:1
  |
3 | enum Bar {
  | --------
  |
    = note: Slice2 enums must have an underlying type. e.g. 'enum Bar : uint8'
    = note: file is using the Slice2 encoding by default
    = note: to use a different encoding, specify it at the top of the slice file. e.g. 'encoding = Slice1

Failed: Compilation failed with 1 error(s)