Skip to content

Improve enum fromOrdinal and valueOf error messages #19178

Closed
@Lasering

Description

@Lasering

Compiler version

3.3.1

Minimized example

enum Foo:
  case A

Foo.fromOrdinal(3)
Foo.valueOf("Bar")

Output Error/Warning message

fromOrdinal

java.util.NoSuchElementException: 3

valueOf

java.lang.IllegalArgumentException: enum case not found: Bar

Why this Error/Warning was not helpful

It does not state from which enum the error has originated, making it harder to track it down.

Suggested improvement

fromOrdinal:

java.util.NoSuchElementException: enum `Foo` has no case with ordinal: 3

valueOf

java.lang.IllegalArgumentException: enum `Foo` has no case with value: Bar

Metadata

Metadata

Assignees

Labels

area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions