feat: add json to tsv and tsv to json#155
Conversation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const json = convertTSVtoJSON(value.trim(), lowercase); | ||
| setOutput(json); | ||
| } catch (errorMessage: unknown) { | ||
| setOutput(errorMessage as string); |
There was a problem hiding this comment.
The caught value is an Error object (thrown by convertTSVtoJSON via throw new Error(...)), but it is cast directly to string. This will display [object Error] in the output textarea instead of the actual error message. You should use (errorMessage instanceof Error ? errorMessage.message : String(errorMessage)) to extract the message properly.
| setOutput(errorMessage as string); | |
| const message = | |
| errorMessage instanceof Error | |
| ? errorMessage.message | |
| : String(errorMessage); | |
| setOutput(message); |
| } catch (errorMessage: unknown) { | ||
| setOutput(errorMessage as string); |
There was a problem hiding this comment.
Same issue as the handleChange catch block: the caught Error object is cast directly to string, which will display [object Error] instead of the actual error message. Use (errorMessage instanceof Error ? errorMessage.message : String(errorMessage)) to properly extract the message.
| const tsv = convertJSONtoTSV(value.trim()); | ||
| setOutput(tsv); | ||
| } catch (errorMessage: unknown) { | ||
| setOutput(errorMessage as string); |
There was a problem hiding this comment.
The caught value is an Error object (thrown by convertJSONtoTSV via throw new Error(...)), but it is cast directly to string. This will display [object Error] in the output textarea instead of the actual error message. Use (errorMessage instanceof Error ? errorMessage.message : String(errorMessage)) to properly extract the message.
| setOutput(errorMessage as string); | |
| const message = | |
| errorMessage instanceof Error | |
| ? errorMessage.message | |
| : String(errorMessage); | |
| setOutput(message); |
| handleChange({ | ||
| currentTarget: { value: SAMPLE_DATA }, | ||
| } as React.ChangeEvent<HTMLTextAreaElement>); | ||
| }, []); |
There was a problem hiding this comment.
handleFillSampleData uses handleChange in its body but has an empty dependency array []. This means it captures a stale reference to the initial handleChange. If the user toggles the "lowercase keys" checkbox and then clicks "Fill Sample Data", the conversion will ignore the lowercase setting because the stale handleChange still closes over lowercase = false. Add handleChange to the dependency array.
| }, []); | |
| }, [handleChange]); |
Summary