This repository was archived by the owner on Apr 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -96,9 +96,13 @@ export class StatsStorage {
96
96
}
97
97
98
98
private loadFromFile ( ) : void {
99
- // 直接读取 JSON 数据
100
- const fileContent = fs . readFileSync ( this . filePath , 'utf8' ) ;
101
- this . data = JSON . parse ( fileContent ) ;
99
+ try {
100
+ const fileContent = fs . readFileSync ( this . filePath , 'utf8' ) ;
101
+ this . data = JSON . parse ( fileContent ) ;
102
+ }
103
+ catch ( e ) {
104
+ this . data = [ ] ;
105
+ }
102
106
}
103
107
104
108
public stopAutoSave ( ) : void {
Original file line number Diff line number Diff line change @@ -111,8 +111,13 @@ export class HourlyStatsStorage {
111
111
}
112
112
113
113
private loadFromFile ( ) : void {
114
- const fileContent = fs . readFileSync ( this . filePath , 'utf8' ) ;
115
- this . data = JSON . parse ( fileContent ) ;
114
+ try {
115
+ const fileContent = fs . readFileSync ( this . filePath , 'utf8' ) ;
116
+ this . data = JSON . parse ( fileContent ) ;
117
+ }
118
+ catch ( e ) {
119
+ this . data = [ ] ;
120
+ }
116
121
}
117
122
118
123
public stopAutoSave ( ) : void {
Original file line number Diff line number Diff line change @@ -66,8 +66,13 @@ export class NumberStorage {
66
66
}
67
67
68
68
private loadFromFile ( ) : void {
69
- const data = fs . readFileSync ( this . filePath , 'utf8' ) ;
70
- this . data = JSON . parse ( data ) ;
69
+ try {
70
+ const data = fs . readFileSync ( this . filePath , 'utf8' ) ;
71
+ this . data = JSON . parse ( data ) ;
72
+ }
73
+ catch ( e ) {
74
+ this . data = [ ] ;
75
+ }
71
76
}
72
77
73
78
public stopAutoSave ( ) : void {
You can’t perform that action at this time.
0 commit comments