-
Notifications
You must be signed in to change notification settings - Fork 22
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
#3216 JQ fromdate error gets cut off in page editor #3336
Changes from 2 commits
0b02d1d
9b0b876
40bca11
60ec87a
c8a2fd0
c53cd0f
1fadfdf
86a7f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,8 @@ import { isNullOrBlank } from "@/utils"; | |||||||
import { InputValidationError } from "@/blocks/errors"; | ||||||||
import { isErrorObject } from "@/errors"; | ||||||||
|
||||||||
const jqStacktraceRegexp = /jq: error \(at \<stdin\>:0\): (?<message>.*)/; | ||||||||
|
||||||||
export class JQTransformer extends Transformer { | ||||||||
override async isPure(): Promise<boolean> { | ||||||||
return true; | ||||||||
|
@@ -66,13 +68,28 @@ export class JQTransformer extends Transformer { | |||||||
// eslint-disable-next-line @typescript-eslint/return-await -- Type is `any`, it throws the rule off | ||||||||
return await jq.promised.json(input, filter); | ||||||||
} catch (error) { | ||||||||
if (!isErrorObject(error) || !error.message.includes("compile error")) { | ||||||||
// The message length check is there because the JQ error message sometimes is cut and if it is we try to parse the stacktrace | ||||||||
// See https://github.com/pixiebrix/pixiebrix-extension/issues/3216 | ||||||||
if ( | ||||||||
!isErrorObject(error) || | ||||||||
(error.message.length > 13 && !error.message.includes("compile error")) | ||||||||
) { | ||||||||
throw error; | ||||||||
} | ||||||||
|
||||||||
const message = error.stack.includes("unexpected $end") | ||||||||
? "Unexpected end of jq filter, are you missing a parentheses, brace, and/or quote mark?" | ||||||||
: "Invalid jq filter, see error log for details"; | ||||||||
let message: string; | ||||||||
if (error.stack.includes("unexpected $end")) { | ||||||||
message = | ||||||||
"Unexpected end of jq filter, are you missing a parentheses, brace, and/or quote mark?"; | ||||||||
} else { | ||||||||
const jqMessageFromStack = jqStacktraceRegexp.exec(error.stack)?.groups | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can write it this way to avoid the nested condition. Prettier will likely improve the wrapping further
Suggested change
|
||||||||
?.message; | ||||||||
if (jqMessageFromStack == null) { | ||||||||
message = "Invalid jq filter, see error log for details"; | ||||||||
} else { | ||||||||
message = jqMessageFromStack.trim(); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
throw new InputValidationError( | ||||||||
message, | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,11 +27,13 @@ import { | |||||
MultipleElementsFoundError, | ||||||
NoElementsFoundError, | ||||||
selectError, | ||||||
serializePixiebrixError, | ||||||
} from "@/errors"; | ||||||
import { range } from "lodash"; | ||||||
import { deserializeError, serializeError } from "serialize-error"; | ||||||
import { InputValidationError, OutputValidationError } from "@/blocks/errors"; | ||||||
import { matchesAnyPattern } from "@/utils"; | ||||||
import { isPlainObject } from "@reduxjs/toolkit"; | ||||||
fregante marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
const TEST_MESSAGE = "Test message"; | ||||||
|
||||||
|
@@ -291,3 +293,22 @@ describe("selectError", () => { | |||||
); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("serializatin", () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
test("serializes error cause", () => { | ||||||
const inputValidationError = new InputValidationError( | ||||||
"test input validation error", | ||||||
null, | ||||||
null, | ||||||
[] | ||||||
); | ||||||
const contextError = new ContextError("text context error", { | ||||||
cause: inputValidationError, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed this was a bug: This is a temporary issue so I wouldn't spend too much time on it 👍 |
||||||
}); | ||||||
|
||||||
const serializedError = serializePixiebrixError(contextError); | ||||||
|
||||||
expect(isPlainObject(serializedError)).toBeTruthy(); | ||||||
expect(isPlainObject(serializedError.cause)).toBeTruthy(); | ||||||
}); | ||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
*/ | ||
|
||
import { MessageContext } from "@/core"; | ||
import { deserializeError, ErrorObject } from "serialize-error"; | ||
import { deserializeError, ErrorObject, serializeError } from "serialize-error"; | ||
import { AxiosError, AxiosResponse } from "axios"; | ||
import { isObject, matchesAnyPattern } from "@/utils"; | ||
import safeJsonStringify from "json-stringify-safe"; | ||
|
@@ -250,6 +250,16 @@ export function isContextError(error: unknown): error is ContextError { | |
); | ||
} | ||
|
||
// The serializeError preserves custom properties that effectively means the "cause" is skipped by the serializer | ||
export function serializePixiebrixError(error: Error): ErrorObject { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we keep this function it needs to be renamed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a link to the issue here? sindresorhus/serialize-error#74 |
||
const serializedError = serializeError(error); | ||
if ("cause" in error) { | ||
serializedError.cause = serializePixiebrixError(error.cause as Error); | ||
} | ||
|
||
return serializedError; | ||
} | ||
|
||
/** | ||
* Returns true iff the root cause of the error was a CancelError. | ||
* @param error the error object | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serializeError
must acceptunknown
;as Error
is unsafely asserting thatunknown
is anError
without actually checking for it.