deepmodeling / deepmodeling/dpgui

[Code scan] Handle missing or invalid custom template files

Open Beginner friendly
#564 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vue
Stars
9
Forks
5
PR merge metrics
No merged PRs in 30d

Description

This issue was found during a Codex global code scan of the repository.

Baseline commit: e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3

Problem

The custom template import path assumes a file is selected and that its contents are valid JSON. Both `reader.readAsText(this.file[0])` and `JSON.parse(e.target.result)` are unguarded.

Code references:
https://github.com/deepmodeling/dpgui/blob/e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3/src/views/NewConfig.vue#L30-L49

Relevant snippet:
```js
const obj = JSON.parse(e.target.result);
```

```js
reader.readAsText(this.file[0]);
```

Impact

Clicking Add without selecting a file, or selecting malformed JSON, throws an uncaught browser error instead of giving a recoverable UI error.

Suggested fix

Disable Add until a file is selected, wrap JSON parsing in `try`/`catch`, handle `FileReader.onerror`, and show a validation message instead of navigating away.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the custom template import flow in src/views/NewConfig.vue, especially lines 30-49. Exercise Add with no file selected and with malformed JSON, then verify both cases show a recoverable validation error rather than an uncaught browser error or navigation away.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.