Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/command_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ auto sourcemeta::jsonschema::fmt(const sourcemeta::core::Options &options)
entry.resolution_base};
}

if (entry.multidocument) {
throw MultiDocumentInputError{
"This command does not support input with multiple documents",
entry.resolution_base};
}

if (!entry.second.is_object() && !entry.second.is_boolean()) {
throw NotSchemaError{entry.resolution_base};
}
Expand Down
7 changes: 7 additions & 0 deletions src/command_lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
entry.resolution_base};
}

if (entry.multidocument) {
throw MultiDocumentInputError{
"The --fix option is not supported for input with multiple "
"documents",
entry.resolution_base};
}

if (!entry.second.is_object() && !entry.second.is_boolean()) {
throw NotSchemaError{entry.resolution_base};
}
Expand Down
18 changes: 18 additions & 0 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ class YAMLInputError : public std::runtime_error {
std::filesystem::path path_;
};

class MultiDocumentInputError : public std::runtime_error {
public:
MultiDocumentInputError(const std::string &message,
std::filesystem::path path)
: std::runtime_error{message}, path_{std::move(path)} {}

[[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
return this->path_;
}

private:
std::filesystem::path path_;
};

class UnsupportedOpenAPIFormatError : public std::runtime_error {
public:
UnsupportedOpenAPIFormatError()
Expand Down Expand Up @@ -1162,6 +1176,10 @@ inline auto try_catch(const sourcemeta::core::Options &options,
const auto is_json{options.contains("json")};
print_exception(is_json, error);
return EXIT_NOT_SUPPORTED;
} catch (const MultiDocumentInputError &error) {
const auto is_json{options.contains("json")};
print_exception(is_json, error);
return EXIT_NOT_SUPPORTED;
} catch (
const sourcemeta::core::FileError<UnsupportedOpenAPIFormatError> &error) {
const auto is_json{options.contains("json")};
Expand Down
Loading
Loading