Skip to content

Incorrect error message when column is unexpectedly NULL #560

@simondean

Description

@simondean

Are you looking for help?

No

Anorm Version (2.5.x / etc)

2.7.0 (latest version)

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

Use uname -a if on Linux.

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

Adopt JDK 11

Library Dependencies

N/A

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. Use the scalar[Int].single on a column that unexpectedly contains a NULL
  2. An error is thrown that says the column unexpectedly contains a null

Actual Behavior

  1. Use the scalar[Int].single on a column that unexpectedly contains a NULL
  2. This error is thrown: anorm.AnormException: '.completed_average' not found, available columns: completed_average, completed_average
  3. The error makes it look like there was an issue with column name or column alias etc. The actual issue was that the column unexpectedly contains a NULL and the scalar[Option[Int]].single needs to be used instead

The issue seems to be with this code in Anorm:

  @inline private def parseColumn[T](
      row: Row,
      name: String,
      c: Column[T],
      input: (Any, MetaDataItem)
  ): Either[SqlRequestError, T] = c.tupled(input).left.map {
    case UnexpectedNullableFound(_) =>
      ColumnNotFound(name, row)

    case cause => cause
  }

The UnexpectedNullableFound error is incorrectly mapped to the ColumnNotFound error

Reproducible Test Case

Please provide a PR with a failing test.

If the issue is more complex or requires configuration, please provide a link to a project on Github that reproduces the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions