Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding failure-capture information to exception message. #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/tmp/
.tags
.DS_Store
/.idea/
8 changes: 7 additions & 1 deletion lib/svelte/errors/version_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ module Svelte
# Svelte error class to represent version errors.
# Raised when a Swagger v1 JSON is fed into Svelte
class VersionError < StandardError

def initialize(supplied_version)
@supplied_version = supplied_version
end

def message
'Invalid Swagger version spec supplied. Svelte supports Swagger v2 only'
%-"swagger" field is #{@supplied_version or 'empty'}. Svelte only supports Swagger v2.0.-

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tradition would be to use %Q{} rather than other delimeters. (Matched delimeters can handle themselves quite well)

end

end
end
5 changes: 3 additions & 2 deletions lib/svelte/swagger_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def validate
end

def validate_version
if raw_hash['swagger'] != '2.0'
raise VersionError
swagger_version = raw_hash['swagger']
if swagger_version != '2.0'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're improving this, and we may wish to extend in the future: pehaps we can define SUPPORTED_SWAGGER_VERSIONS as a constant, and check our version's inclusion in that?

raise VersionError.new(swagger_version)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/svelte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
it 'raises a VersionError exception' do
expect { described_class.create(json: json, module_name: module_name) }
.to raise_error(Svelte::VersionError,
'Invalid Swagger version spec supplied. Svelte supports Swagger v2 only')
'"swagger" field is empty. Svelte only supports Swagger v2.0.')
end
end
end
Expand Down