Closed Bug 1357001 Opened 7 years ago Closed 7 years ago

Improve Telemetry python script errors

Categories

(Toolkit :: Telemetry, enhancement, P1)

enhancement
Points:
2

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: gfritzsche, Assigned: gfritzsche)

Details

(Whiteboard: [measurement:client])

Attachments

(5 files, 3 obsolete files)

Currently we throw errors from the histogram, scalar & event parsing python scripts when a condition is not met.
This produces hard to read errors.

We should refactor this to show clear error messages while still failing the build.

We may want to merge the probe-scraper updates into m-c [1] before this, to avoid further rebasing pain later.

1: https://github.com/mozilla/probe-scraper/issues/6
Attached patch First cut (obsolete) — Splinter Review
Assignee: nobody → gfritzsche
Priority: P2 → P1
Comment on attachment 8858770 [details] [diff] [review]
First cut

Review of attachment 8858770 [details] [diff] [review]:
-----------------------------------------------------------------

Some notes.

::: toolkit/components/telemetry/Histograms.json
@@ +5,5 @@
>      "description": "has accessibility support been instantiated"
>    },
>    "A11Y_CONSUMERS": {
>      "expires_in_version": "default",
> +    "kind": "count",

Uh... I don't think this is allowed.

::: toolkit/components/telemetry/gen-histogram-data.py
@@ +180,5 @@
>  def main(output, *filenames):
> +    try:
> +        histograms = list(histogram_tools.from_files(filenames))
> +    except histogram_tools.BuildError as ex:
> +        print("\nError processing histograms:\n" + str(ex) + "\n")

Can we be more specific? "Error processes histograms when generating histogram data: "

::: toolkit/components/telemetry/gen-histogram-enum.py
@@ +45,5 @@
>      # Load the histograms.
> +    try:
> +        all_histograms = list(histogram_tools.from_files(filenames))
> +    except histogram_tools.BuildError as ex:
> +        print("\nError processing histograms:\n" + str(ex) + "\n")

Ditto: "Error processing histograms when generating histogram enum: "

::: toolkit/components/telemetry/histogram_tools.py
@@ +453,5 @@
>                  definition['n_buckets'])
>  
>  
>  # This hook function loads the histograms into an OrderedDict.
> +# It will raise a Exception if duplicate keys are found.

It raises a BuildError, specifically.

@@ +471,5 @@
>  def from_Histograms_json(filename):
>      with open(filename, 'r') as f:
>          try:
>              histograms = json.load(f, object_pairs_hook=load_histograms_into_dict)
>          except ValueError, e:

This change is all about removing the ValueErrors, no?
(In reply to Chris H-C :chutten from comment #2)
> Comment on attachment 8858770 [details] [diff] [review]
> First cut
> 
> Review of attachment 8858770 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Some notes.

This was a WIP patch, no need to review yet.
Attachment #8858770 - Attachment is obsolete: true
Comment on attachment 8859245 [details] [diff] [review]
Part 1 - Unify validation errors in probe parsing scripts

@gps:
Looking at the pattern used in e.g. gen-histogram-data.py, does that look good for you from a build perspective?

The motivation here is to stop throwing exception stacks at developers for errors in Histograms.json, instead giving them only clear error messages.
So i'm changing the Telemetry build scripts to do the following on errors:
- print error messages with N lines and (just `print()` them)
- fail the build (using `sys.exit(1)`)
Attachment #8859245 - Flags: review?(chutten)
Attachment #8859245 - Flags: feedback?(gps)
Comment on attachment 8859246 [details] [diff] [review]
Part 2 - Make histogram error message style more consistent

Besides fixing the messages, i also removed the table_dispatch() helper.
It was giving a very unspecific error message, which seems to better fit on the callers side.
Looking through its uses, i still find table_dispatch() rather hard to read and don't see big value in it.
So i decided to just remove it and refactor table handling a bit.
Attachment #8859246 - Flags: review?(chutten)
Comment on attachment 8859245 [details] [diff] [review]
Part 1 - Unify validation errors in probe parsing scripts

Review of attachment 8859245 [details] [diff] [review]:
-----------------------------------------------------------------

Seems straightforward enough.

::: toolkit/components/telemetry/histogram_tools.py
@@ +451,5 @@
>                  definition['n_buckets'])
>  
>  
>  # This hook function loads the histograms into an OrderedDict.
> +# It will raise a Exception if duplicate keys are found.

May as well say ParserError, no?
Attachment #8859245 - Flags: review?(chutten) → review+
Attachment #8859247 - Flags: review?(chutten)
Attachment #8859248 - Flags: review?(chutten)
Attachment #8860394 - Flags: review?(chutten)
(In reply to Georg Fritzsche [:gfritzsche] from comment #8)
> Created attachment 8860394 [details] [diff] [review]
> Part 5 - Fix linting errors

I should roll this into the other patches, but that would mean a lot of re-basing for the later ones.
Comment on attachment 8859246 [details] [diff] [review]
Part 2 - Make histogram error message style more consistent

Review of attachment 8859246 [details] [diff] [review]:
-----------------------------------------------------------------

I don't think you should remove table_dispatch. It's been running fine since it was introduced.

If you feel it must go, at least split it into its own commit. It has little to do with the error message improvements going on in this patch.

::: toolkit/components/telemetry/gen-histogram-data.py
@@ +129,5 @@
>  
>      for histogram in histograms:
> +        kind = histogram.kind()
> +        if not kind in table:
> +            raise Exception('Unknown kind "%s" for histogram "%s".' % (kind, histogram.name()))

You're switching from ParserError to Exception. Deliberately?
Attachment #8859246 - Flags: review?(chutten) → review-
Attachment #8859247 - Flags: review?(chutten) → review+
Attachment #8859248 - Flags: review?(chutten) → review+
Attachment #8860394 - Flags: review?(chutten) → review+
Comment on attachment 8859245 [details] [diff] [review]
Part 1 - Unify validation errors in probe parsing scripts

Review of attachment 8859245 [details] [diff] [review]:
-----------------------------------------------------------------

This is fine. With the exception of raising BaseException, you could have done the same thing by adding "except Exception" everywhere you now use "except ParseError." But it's good practice to have a dedicated error type. So how this is implemented definitely isn't wrong.

::: toolkit/components/telemetry/histogram_tools.py
@@ -86,5 @@
>              whitelists = json.load(f)
>              for name, whitelist in whitelists.iteritems():
>                  whitelists[name] = set(whitelist)
>          except ValueError, e:
> -            raise BaseException('error parsing whitelist (%s)' % whitelist_path)

BaseException should never be raised directly. Raise Exception for a generic error instead.

The reason is special exceptions like KeyboardInterrupt, SystemExit, and GeneratorExit inherit from BaseException whereas Exception is in a different tree from these special exceptions. A catch-almost-everything exception handler is written as "except Exception" so it doesn't catch these special exceptions. The bareword "except:" catches BaseException which can lead to e.g. swallowing ^C requests.
Attachment #8859245 - Flags: feedback?(gps) → feedback+
(In reply to Chris H-C :chutten from comment #13)
> I don't think you should remove table_dispatch. It's been running fine since
> it was introduced.
> 
> If you feel it must go, at least split it into its own commit. It has little
> to do with the error message improvements going on in this patch.

My main problem is that we want specific error messages across the code.
Also passing error messages as parameters i don't see the value of this function anymore.

I wonder what this gains us over just putting the three lines at the caller site.
If instead i just put those three lines at the caller site, i don't have to look up anymore what this function does (i regularly do that).

Any better suggestions for the error message and readability?
Flags: needinfo?(chutten)
(In reply to Chris H-C :chutten from comment #13)
> ::: toolkit/components/telemetry/gen-histogram-data.py
> @@ +129,5 @@
> >  
> >      for histogram in histograms:
> > +        kind = histogram.kind()
> > +        if not kind in table:
> > +            raise Exception('Unknown kind "%s" for histogram "%s".' % (kind, histogram.name()))
> 
> You're switching from ParserError to Exception. Deliberately?

Yes - i've been using ParserError for "error message for parsing/validation failures the user needs to see and possibly fix".

Not finding the `kind` here in the table is a programming error that we might want to see a stack for, so i don't think this should be a ParserError.
Comment on attachment 8859246 [details] [diff] [review]
Part 2 - Make histogram error message style more consistent

Review of attachment 8859246 [details] [diff] [review]:
-----------------------------------------------------------------

Very well.
Attachment #8859246 - Flags: review- → review+
Flags: needinfo?(chutten)
Attachment #8862602 - Attachment description: Part 1 - Unify validation errors in probe parsing scripts. f=gps → Part 1 - Unify validation errors in probe parsing scripts. r=chutten, f=gps
Attachment #8862602 - Flags: review+
Attachment #8862603 - Attachment description: Part 2 - Make histogram error message style more consistent → Part 2 - Make histogram error message style more consistent. r=chutten
Attachment #8862603 - Flags: review+
Attachment #8859245 - Attachment is obsolete: true
Attachment #8859246 - Attachment is obsolete: true
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/29237e2192a9
Part 1 - Unify validation errors in probe parsing scripts. r=chutten, f=gps
https://hg.mozilla.org/integration/mozilla-inbound/rev/a73ed8eaedf9
Part 2 - Make histogram error message style more consistent. r=chutten
https://hg.mozilla.org/integration/mozilla-inbound/rev/c55c6f471cfb
Part 3 - Make scalar error messages style more consistent. r=chutten
https://hg.mozilla.org/integration/mozilla-inbound/rev/b439880e27a1
Part 4 - Make event error messages style more consistent. r=chutten
https://hg.mozilla.org/integration/mozilla-inbound/rev/5cf54ffdded1
Part 5 - Fix linting errors. r=chutten
Keywords: checkin-needed
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: