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

adds error messages for syntax errors #3486

Merged
merged 5 commits into from
Aug 22, 2024
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
8 changes: 6 additions & 2 deletions apps/dashboard/app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ def opts
{}
end
@opts.symbolize_keys.compact
rescue Errno::ENOENT, SyntaxError # File does not exist or syntax errors
rescue Errno::ENOENT # File does not exist
Rails.logger.warn "Announcement file not found: #{@path}"
@opts = {}
rescue StandardError => e
rescue SyntaxError => e # Syntax errors
Rails.logger.warn "Syntax error in announcement file '#{@path}': #{e.message}. Please check the file for proper syntax."
@opts = {}
rescue StandardError => e # Other exceptions
Rails.logger.warn "Error parsing announcement file '#{@path}': #{e.message}"
@opts = {}
end
Expand Down
10 changes: 10 additions & 0 deletions apps/dashboard/test/models/announcements_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ class AnnouncementsTest < ActiveSupport::TestCase
assert_equal 0, announcements.select(&:valid?).count
end

test 'should create announcement for syntax error' do
f = Tempfile.open(['announcement', '.yml'])
f.write('<%- end %>')
f.close

Rails.logger.expects(:warn).with(regexp_matches(/Syntax error in announcement file/))
announcement = Announcements.all(f.path).first
assert_equal(:warning, announcement.type)
end

test 'should create invalid announcement for invalid yaml file' do
f = Tempfile.open(['announcement', '.yml'])
f.write %(INVALID: YAML\nINVALID YAML)
Expand Down
Loading