Opened 9 months ago

Closed 9 months ago

#28494 closed enhancement (worksforme)

Please provide an equivalent for UnparseableDescriptor from metrics-lib

Reported by: irl Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Normal Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

When something wasn't able to be parsed, we'd still like to be able to save the bytes to be able to analyse it later. Instead of throwing a TypeError, please allow for an UnparseableDescriptor to be returned instead. This could be behaviour that is switched by a keyword argument on parse_file (and parse_bytes once implemented) or it could just be the default to try it hardest to return something instead of throwing the error.

https://metrics.torproject.org/metrics-lib/org/torproject/descriptor/UnparseableDescriptor.html

Child Tickets

Change History (4)

comment:1 Changed 9 months ago by atagar

Hi irl, sorry about the delay. You filed quite a few interesting tickets. :P

Are you using parse_file() or a DescriptorReader? parse_file() is documented as only raising TypeErrors when unable to determine the descriptor type ("TypeError if we can't match the contents of the file to a descriptor type"), and from my read of the code looks like it does. The DescriptorReader however raises TypeErrors as a catch-all for parsing failures.

Honestly I'm a little tempted to deprecate our DescriptorReader. I wrote it for Karsten way back when I first began Stem and he asked for a class that tracked when unprocessed files become available on disk. I've never used it, and it's such a specialized use case I'm unaware of anyone else using it either.

Do you need this class or would parse_file() work just as well for you?

comment:2 Changed 9 months ago by irl

I'm using parse_file() at the moment. If we turn this prototype into a full CollecTor replacement then we might need something that looks like DescriptorReader, but we also might not. We could always move this functionality into bushel and just use parse_file() from stem.

comment:3 Changed 9 months ago by atagar

Great! Glad to hear you're not using the DescriptorReader.

If you're using parse_file() then I'm unsure if there's anything to do with this. If you include 'validate = True' invalid content will raise ValueErrors, and if not it should pretty much always return a Descriptor object. TypeErrors only arise when unable to determine the descriptor type (which is caller error).

Am I missing anything or can this be closed?

comment:4 Changed 9 months ago by irl

Resolution: worksforme
Status: newclosed

Ok. In this case I think this can be closed. If I do find that there are cases where it's not working, I'll reopen or file a new ticket.

Note: See TracTickets for help on using tickets.