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

Handle Error stored in redux trace.traces #195

Merged
merged 2 commits into from
Mar 13, 2018
Merged
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions src/model/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const isErrorTag = ({ key, value }) => key === 'error' && (value === true || val
* @param trace Trace data in the format sent over the wire.
* @return {TraceSummary} Summary of the trace data for use in the search results.
*/
export function getTraceSummary(trace: Trace): TraceSummary {
export function getTraceSummary(trace: Trace | Error): ?TraceSummary {
if (trace instanceof Error) {
return null;
}
const { processes, spans, traceID } = trace;

let traceName = '';
Expand Down Expand Up @@ -83,7 +86,7 @@ export function getTraceSummary(trace: Trace): TraceSummary {
* @return {TraceSummaries} The `{ traces, maxDuration }` value.
*/
export function getTraceSummaries(_traces: Trace[]): TraceSummaries {
const traces = _traces.map(getTraceSummary);
const traces = _traces.map(getTraceSummary).filter(Boolean);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I am following the typing here: _traces is an array of Trace objects, how could getTraceSummary function be called with an Error object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an inefficiency or irregularity in the state of static typing in the repo. Some files have flow-types and some do not.

The type here is really (Trace | Error)[].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so maybe the fix should be (using Scala-ish notation)

_traces.filterNot(_ instanceof Error).map(getTraceSummary);

?

or even do the filtering somewhere upstream, instead of propagating the mixed type deeper.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. At the least, if it's possible for there to be Error objects present, the parameter type should be annotated like you described, getTraceSummaries(_traces: (Trace | Error)[]): TraceSummaries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurishkuro Great point. I will filter then get the summary. I don't want to filter it further upstream because the presence of the error will be useful in resolving #51.

@simonrobb 👍

Note, the following code was not possible due to Flow flagging it as an error:

const traces = _traces.filter(item => !(item instanceof Error)).map(getTraceSummary);

const maxDuration = Math.max(..._map(traces, 'duration'));
return { maxDuration, traces };
}
Expand Down