Skip to content

Commit

Permalink
Reword error messages to please TCK
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Jul 9, 2018
1 parent 49e03da commit 7627f79
Showing 1 changed file with 26 additions and 6 deletions.
Expand Up @@ -896,7 +896,14 @@ public static TextValue toString( AnyValue in )
} }
else if ( in instanceof Value ) else if ( in instanceof Value )
{ {
return stringValue( ((Value) in).prettyPrint() ); if ( in instanceof PointValue )
{
return stringValue( in.toString() );
}
else
{
return stringValue( ((Value) in).prettyPrint() );
}
} }
else else
{ {
Expand Down Expand Up @@ -989,11 +996,13 @@ private static boolean containsNull( MapValue map )


private static AnyValue listAccess( SequenceValue container, AnyValue index ) private static AnyValue listAccess( SequenceValue container, AnyValue index )
{ {
if ( !(index instanceof IntegralValue) ) NumberValue number = asNumberValue( index );
if ( !(number instanceof IntegralValue) )
{ {
throw new CypherTypeException( format( "Expected %s to be an integer", index), null ); throw new CypherTypeException( format( "Cannot index a list using an non-integer number, got %s", number ),
null );
} }
long idx = ((IntegralValue) index).longValue(); long idx = number.longValue();
if ( idx > Integer.MAX_VALUE || idx < Integer.MIN_VALUE ) if ( idx > Integer.MAX_VALUE || idx < Integer.MIN_VALUE )
{ {
throw new InvalidArgumentException( throw new InvalidArgumentException(
Expand Down Expand Up @@ -1022,11 +1031,22 @@ private static String asString( AnyValue value )
{ {
if ( !(value instanceof TextValue) ) if ( !(value instanceof TextValue) )
{ {
throw new CypherTypeException( format( "Expected %s to be a string", value), null ); throw new CypherTypeException( format( "Expected %s to be a %s, but it was a %s", value,
TextValue.class.getName(), value.getClass().getName()), null );
} }
return ((TextValue) value).stringValue(); return ((TextValue) value).stringValue();
} }


private static NumberValue asNumberValue( AnyValue value )
{
if ( !(value instanceof NumberValue) )
{
throw new CypherTypeException( format( "Expected %s to be a %s, but it was a %s", value,
NumberValue.class.getName(), value.getClass().getName() ), null );
}
return (NumberValue) value;
}

private static Value calculateDistance( PointValue p1, PointValue p2 ) private static Value calculateDistance( PointValue p1, PointValue p2 )
{ {
if ( p1.getCoordinateReferenceSystem().equals( p2.getCoordinateReferenceSystem() ) ) if ( p1.getCoordinateReferenceSystem().equals( p2.getCoordinateReferenceSystem() ) )
Expand All @@ -1053,7 +1073,7 @@ private static long asLong( AnyValue value )


private static int asInt( AnyValue value ) private static int asInt( AnyValue value )
{ {
return (int) asLong( value ); return (int) asLong( value );
} }


private static CypherTypeException needsNumbers( String method ) private static CypherTypeException needsNumbers( String method )
Expand Down

0 comments on commit 7627f79

Please sign in to comment.