27
27
// RootModule is the global module instance that will create instances of our
28
28
// module for each VU.
29
29
RootModule struct {
30
- // FIXME: we end up instantiating the data module ourselves, which would live side by side with other
31
- // usages of the data module. This works, but might not be ideal. Is there a way for us to import the module
32
- // in a way that we reuse a global test scope's data module instance?
33
30
dataModuleInstance * data.Data
34
31
}
35
32
@@ -78,7 +75,8 @@ func (mi *ModuleInstance) Exports() modules.Exports {
78
75
79
76
// Parser is a CSV parser.
80
77
type Parser struct {
81
- CurrentLine atomic.Int64
78
+ // currentLine holds the current line number being read by the parser.
79
+ currentLine atomic.Int64
82
80
83
81
// reader is the CSV reader that enables to read records from the provided
84
82
// input file.
@@ -104,7 +102,7 @@ func (mi *ModuleInstance) Parse(file sobek.Value, options sobek.Value) *sobek.Pr
104
102
// 1. Make sure the Sobek object is a fs.File (sobek operation)
105
103
var fileObj fs.File
106
104
if err := mi .vu .Runtime ().ExportTo (file , & fileObj ); err != nil {
107
- reject (fmt .Errorf ("first arg doesn't appear to be a *file .File instance, it's %T" , file ))
105
+ reject (fmt .Errorf ("first argument expected to be a fs .File instance, got %T instead " , file ))
108
106
return promise
109
107
}
110
108
@@ -113,7 +111,7 @@ func (mi *ModuleInstance) Parse(file sobek.Value, options sobek.Value) *sobek.Pr
113
111
var err error
114
112
parserOptions , err = newParserOptionsFrom (options .ToObject (rt ))
115
113
if err != nil {
116
- reject (fmt .Errorf ("encountered an error while interpreting Parser options; reason: %w" , err ))
114
+ reject (fmt .Errorf ("failed to interpret the provided Parser options; reason: %w" , err ))
117
115
return promise
118
116
}
119
117
}
@@ -147,13 +145,16 @@ func (mi *ModuleInstance) NewParser(call sobek.ConstructorCall) *sobek.Object {
147
145
}
148
146
149
147
if len (call .Arguments ) < 1 || sobek .IsUndefined (call .Argument (0 )) {
150
- common .Throw (rt , fmt .Errorf ("parser constructor takes at least one non-nil source argument" ))
148
+ common .Throw (rt , fmt .Errorf ("csv Parser constructor takes at least one non-nil source argument" ))
151
149
}
152
150
153
- // 1. Make sure the Sobek object is a fs.File (sobek operation)
151
+ // 1. Make sure the Sobek object is a fs.File (Sobek operation)
154
152
var file fs.File
155
153
if err := mi .vu .Runtime ().ExportTo (call .Argument (0 ), & file ); err != nil {
156
- common .Throw (mi .vu .Runtime (), fmt .Errorf ("first arg doesn't appear to be a *file.File instance" ))
154
+ common .Throw (
155
+ mi .vu .Runtime (),
156
+ fmt .Errorf ("first argument expected to be a fs.File instance, got %T instead" , call .Argument (0 )),
157
+ )
157
158
}
158
159
159
160
options := newDefaultParserOptions ()
@@ -200,7 +201,7 @@ func (p *Parser) Next() *sobek.Promise {
200
201
}
201
202
}
202
203
203
- p .CurrentLine .Add (1 )
204
+ p .currentLine .Add (1 )
204
205
205
206
resolve (parseResult {Done : done , Value : records })
206
207
}()
0 commit comments