NAME

App::Actions::Schema::Invalid - the error for a document that does not match its schema

SYNOPSIS

Catch it after a check:

use App::Actions::Schema qw(assert_valid);

eval { assert_valid($document, $schema, 'the report does not match its schema'); 1 }
	or do {
		my $error = $@;
		if (ref $error && $error->isa('App::Actions::Schema::Invalid')) {
			print STDERR $error->message;
			exit App::Actions::Schema::invalid_exit();
		}
		die $error;
	};

Ask by code, as for any App::Actions::Error:

if (my $error = App::Actions::Error->caught($@)) {
	exit 70 if $error->is('schema.invalid');
}

Throw one yourself:

die App::Actions::Schema::Invalid->new("my document: \$.name: missing\n");

DESCRIPTION

"assert_valid" in App::Actions::Schema throws this object when a document does not match its schema. It is an App::Actions::Error, so it has every method that class has. Three things are always the same:

  • its code is schema.invalid;

  • its location is empty, because the problem is in a document, not at a place in the program;

  • so, as a string, it is exactly its message, with the newline at the end if the message has one. die and warn print it unchanged.

METHODS

new

my $error = App::Actions::Schema::Invalid->new($message);

Makes the error.

ARGUMENTS

  • $message - the whole text to show. End it with a newline if it is a complete line.

RETURNS

The new object. All the methods of App::Actions::Error work on it, for example message, code and is.

SIDE EFFECTS

None. The object is returned, not thrown; use die to throw it.

EXAMPLE

my $error = App::Actions::Schema::Invalid->new("\$.jobs: missing\n");
print $error->code;       # schema.invalid
print "$error";           # $.jobs: missing

API SPECIFICATION

INPUT

{ message => { type => 'string', min => 1 } }

OUTPUT

{ type => 'object', isa => 'App::Actions::Schema::Invalid' }

MESSAGES

None.

COMMON PITFALLS

  • Check the class or code, not the text. The message text can change between releases. Use isa('App::Actions::Schema::Invalid') or is('schema.invalid').

  • The newline is part of the message. message returns it too, so chomp the text if you put it inside another sentence.

ENCODING

The message is a Perl character string and may contain any Unicode text, including emoji. Encode it (for example with binmode STDERR, ':encoding(UTF-8)') before you print it.

AUTHOR

Nigel Horne, njh@nigelhorne.com

FORMAL SPECIFICATION

This section describes the routine in the Z notation. You do not need it to use the module. A name ending in ? is an input and one ending in ! is an output. Error is the state described in "FORMAL SPECIFICATION" in App::Actions::Error.

new

┌─ NewInvalid ──────────────────────────────────────
│ message? : seq CHAR
│ e!       : Error
├───────────────────────────────────────────────────
│ e!.code = "schema.invalid"
│ e!.message = message?
│ e!.location = ⟨⟩
│ string(e!) = message?
└───────────────────────────────────────────────────

STATE DIAGRAM

The object never changes after it is made:

   new($message)              die $error              caught / isa / is
--------------------> +-----------+ ----------> +--------+ -----------------> handled
                      |  CREATED  |             | THROWN |   (e.g. exit 70)
                      +-----------+             +--------+
                                                    |
                                                    | not caught
                                                    v
                                           program stops; STDERR shows
                                           the message, with no location

LICENSE AND COPYRIGHT

Copyright 2026 Nigel Horne.

This program is released under the GNU General Public License, version 2. See the LICENSE file that comes with this distribution. If you use it, please let me know.