[tor-bugs] #16225 [Metrics/metrics-lib]: Unify exception/error handling in metrics-lib
Tor Bug Tracker & Wiki
blackhole at torproject.org
Tue May 9 14:43:08 UTC 2017
#16225: Unify exception/error handling in metrics-lib
---------------------------------+-----------------------------------
Reporter: karsten | Owner: karsten
Type: enhancement | Status: needs_information
Priority: Medium | Milestone: metrics-lib 1.7.0
Component: Metrics/metrics-lib | Version:
Severity: Normal | Resolution:
Keywords: | Actual Points:
Parent ID: | Points:
Reviewer: | Sponsor:
---------------------------------+-----------------------------------
Comment (by iwakeh):
Replying to [comment:8 karsten]:
> ...
> > From this scenario, I would conclude that methods like
readDescriptors, parseDescriptors, collectDescriptors don't throw
DescriptorParseExceptions, but simply process as much as possible and
provide a list of problematic descriptors at the end, which the API using
program can choose to ignore or process.
> > Does this sound like the right use-case description?
>
> It does sound like the right use-case description!
Maybe, add that to the javadoc somewhere :-)
>
> The part that needs more thoughts is when and how we should provide
problematic descriptors and related error cases. Providing them at the
end can easily lead to out-of-memory situations, because we might have to
keep more and more problematic descriptors in memory until we're finally
done parsing. Maybe we can include problematic descriptors in line with
non-problematic ones.
>
> How about this: whenever we can't parse a descriptor, we include a
`Descriptor` instance with the raw contents we cannot parse in the
descriptor queue. And we include a new method `Descriptor#getException()`
that returns the `DescriptorParseException` that we ran into, or `null` if
we didn't run into an exception while parsing.
>
> Similarly, if we run into an exception while downloading files from a
remote server or while reading files from the file system, so before
splitting contents into descriptor-sized chunks and attempting to parse
those, we include a `Descriptor` instance without descriptor contents and
with just the exception.
If we were using java8, I'd suggest using java.util.Optional<Descriptor>.
Actually your suggestions goes in that direction, too.
Maybe, a new descriptor class InvalidDescriptor could be useful here? It
would be accessible via the instanceof-method and have limited
information: at least the Exception and maybe also its origin (url, path),
in case of a file also bytes.
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/16225#comment:10>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list