Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Jul 15, 2024
1 parent cdbc925 commit d01daef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 3 additions & 9 deletions packages/jaeger-ui/src/utils/readJsonFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,14 @@ describe('fileReader.readJsonFile', () => {
return expect(p).rejects.toMatchObject(expect.any(Error));
});

it('rejects on malform JSON', () => {
it('rejects malformed JSON', () => {
const file = new File(['not-json'], 'foo.json');
const p = readJsonFile({ file });
return expect(p).rejects.toMatchObject(expect.any(Error));
});

it('loads multiple JSON data', () => {
let fileContent;
try {
fileContent = fs.readFileSync('src/utils/fixtures/otlp2jaeger-multi-in.json.txt', 'utf-8');
} catch (err) {
console.error('Error reading file:', err);
throw err;
}
it('loads JSON-per-line data', () => {
let fileContent = fs.readFileSync('src/utils/fixtures/otlp2jaeger-multi-in.json.txt', 'utf-8');
const file = new File([fileContent], 'multi.json', { type: 'application/json' });
const p = readJsonFile({ file });
expect(p).resolves.toBeDefined();
Expand Down
4 changes: 2 additions & 2 deletions packages/jaeger-ui/src/utils/readJsonFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function tryParseMultiLineInput(input: string): any[] {
const traceObj = JSON.parse(jsonString.trim());
parsedObjects.push(traceObj);
} catch (error) {
throw new Error(`Error parsing JSON at line ${index+1}: ${(error as Error).message}`);
throw new Error(`Error parsing JSON at line ${index + 1}: ${(error as Error).message}`);
}
});

Expand All @@ -45,7 +45,7 @@ export default function readJsonFile(fileList: { file: File }): Promise<string>
try {
traceObj = tryParseMultiLineInput(reader.result);
} catch (error) {
reject(new Error(`Error processing JSON: ${(error as Error).message}`));
reject(error);
return;
}
}
Expand Down

0 comments on commit d01daef

Please sign in to comment.