floci-io/floci · error · CoercingParseValueException

Invalid AWSDateTime: {}

Error message

Invalid AWSDateTime: {}

What it means

Thrown by the AWSDateTime scalar's parseValue when the string cannot be parsed as an ISO-8601 instant. The coercion uses java.time.Instant.parse, which only accepts ISO-8601 formatted instant strings in UTC such as 2024-01-15T10:30:00Z (with optional fractional seconds).

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/appsync/graphql/scalars/AppSyncScalars.java:73

            }
        })
        .build();

    public static final GraphQLScalarType AWS_DATE_TIME = GraphQLScalarType.newScalar()
        .name("AWSDateTime")
        .description("An ISO-8601 datetime string")
        .coercing(new Coercing<String, String>() {
            @Override
            public String serialize(Object dataFetcherResult) {
                return dataFetcherResult != null ? dataFetcherResult.toString() : null;
            }
            @Override
            public String parseValue(Object input) {
                String str = input.toString();
                try {
                    Instant.parse(str);
                } catch (DateTimeParseException e) {
                    throw new CoercingParseValueException("Invalid AWSDateTime: " + str);
                }
                return str;
            }
            @Override
            public String parseLiteral(Object input) {
                if (!(input instanceof StringValue sv)) return null;
                return parseValue(sv.getValue());
            }
        })
        .build();

    public static final GraphQLScalarType AWS_DATE = GraphQLScalarType.newScalar()
        .name("AWSDate")
        .description("An ISO-8601 date string (yyyy-MM-dd)")
        .coercing(new Coercing<String, String>() {
            @Override
            public String serialize(Object dataFetcherResult) {
                return dataFetcherResult != null ? dataFetcherResult.toString() : null;

View on GitHub (pinned to 62ff490619)

Solutions

  1. Normalize to UTC and format with DateTimeFormatter.ISO_INSTANT: Instant.now().toString() or DateTimeFormatter.ISO_INSTANT.format(zdt.toInstant())
  2. If the source has an offset, convert first: offsetDateTime.toInstant().toString()
  3. Never use SimpleDateFormat patterns or Date.toString() for AWSDateTime fields
  4. Add a client-side check: try { Instant.parse(s); } catch before sending

Example fix

// before
String when = zonedDateTime.toString(); // 2024-01-15T10:30+02:00 -> throws

// after
String when = zonedDateTime.toInstant().toString(); // 2024-01-15T08:30:00Z
Defensive patterns

Strategy: validation

Validate before calling

static String toAwsDateTime(Instant i) { return i.toString(); }
static boolean validAwsDateTime(String s) { try { Instant.parse(s); return true; } catch (DateTimeParseException e) { return false; } }
if (!validAwsDateTime(s)) throw new IllegalArgumentException("AWSDateTime must be ISO-8601 UTC like 2024-01-15T10:30:00Z");

Type guard

// TS
const isAwsDateTime = (s: string): boolean => !isNaN(Date.parse(s)) && /Z$/.test(s);

Try / catch

catch (CoercingParseValueException e) { // show field name + expected ISO-8601 UTC format to the user }

Prevention

When it happens

Trigger: A GraphQL request supplies an AWSDateTime variable like "2024-01-15 10:30:00" (space separator), "2024-01-15T10:30:00+02:00" (offset, not Z), "01/15/2024", or an epoch-millis number rendered as string. Instant.parse fails on each and the coercion throws.

Common situations: Formatting dates with a locale-dependent formatter (MM/dd/yyyy); forgetting to convert a ZonedDateTime/OffsetDateTime to UTC before sending; serializing java.util.Date via toString() which yields "Mon Jan 15 ..."; database or frontend timestamps that carry a local offset.

Related errors


AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14). Data as JSON: /api/errors/cb06123fff7a9a2b. Report an issue: GitHub.