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

Remove XML::Error.errors #14936

Open
wants to merge 2 commits into
base: master
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
10 changes: 0 additions & 10 deletions spec/std/xml/reader_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,5 @@ module XML

reader.errors.map(&.to_s).should eq ["Opening and ending tag mismatch: people line 1 and foo"]
end

it "adds errors to `XML::Error.errors` (deprecated)" do
XML::Error.errors # clear class error list

reader = XML::Reader.new(%(<people></foo>))
reader.read
reader.expand?

XML::Error.errors.try(&.map(&.to_s)).should eq ["Opening and ending tag mismatch: people line 1 and foo"]
end
end
end
15 changes: 1 addition & 14 deletions src/xml/error.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,9 @@ class XML::Error < Exception
super(message)
end

@@errors = [] of self

# :nodoc:
protected def self.add_errors(errors)
@@errors.concat(errors)
end

@[Deprecated("This class accessor is deprecated. XML errors are accessible directly in the respective context via `XML::Reader#errors` and `XML::Node#errors`.")]
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
def self.errors : Array(XML::Error)?
if @@errors.empty?
nil
else
errors = @@errors.dup
@@errors.clear
errors
end
{% raise "`XML::Error.errors` was removed because it leaks memory when it's not used. XML errors are accessible directly in the respective context via `XML::Reader#errors` and `XML::Node#errors`.\nSee https://github.com/crystal-lang/crystal/issues/14934 for details. " %}
end

def self.collect(errors, &)
Expand Down
4 changes: 1 addition & 3 deletions src/xml/reader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ class XML::Reader
end

private def collect_errors(&)
Error.collect(@errors) { yield }.tap do
Error.add_errors(@errors)
end
Error.collect(@errors) { yield }
end

private def check_no_null_byte(attribute)
Expand Down
Loading