MCPcopy Create free account
hub / github.com/copernet/copernicus / newScriptErrChecker

Function newScriptErrChecker

logic/lscript/lscript_test.go:160–205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

158}
159
160func newScriptErrChecker() (*scriptErrChecker, error) {
161 // Construction of errtable([]string) from errcode/scripterror.go
162 var sec scriptErrChecker
163 b, err := ioutil.ReadFile("../../errcode/scripterror.go")
164 if err != nil {
165 err = fmt.Errorf("scripterr.go not found")
166 return nil, err
167 }
168 content := string(b)
169 index := strings.Index(content, "const")
170 if index == -1 {
171 err = fmt.Errorf("scripterr.go does not contain \"const\"")
172 return nil, err
173 }
174 content = content[index:]
175 index = strings.Index(content, ")")
176 if index == -1 {
177 err = fmt.Errorf("scripterr.go const without \")\"")
178 return nil, err
179 }
180 content = content[:index]
181 contents := strings.Split(content, "\n")
182 if contents[0] != "const (" {
183 err = fmt.Errorf("scripterr.go \"const (\" should be the first line")
184 return nil, err
185 }
186 if strings.HasSuffix(contents[1], " ScriptErr = ScriptErrorBase + iota") {
187 contents[1] = strings.TrimSuffix(contents[1], " ScriptErr = ScriptErrorBase + iota")
188 } else {
189 err = fmt.Errorf("scripterr.go the first const should be declared ending with \" ScriptErr = ScriptErrorBase + iota\"")
190 return nil, err
191 }
192 contents = contents[1:]
193 sec.errtable = []string{}
194 for _, line0 := range contents {
195 line := strings.Replace(line0, "\n", "", -1)
196 line = strings.Replace(line, "\t", "", -1)
197 line = strings.Replace(line, " ", "", -1)
198 if line == "" || strings.HasPrefix(line, "//") || strings.HasPrefix(line, "/*") {
199 continue
200 }
201 sec.errtable = append(sec.errtable, line)
202 }
203 // got errtable
204 return &sec, nil
205}
206
207func (sec *scriptErrChecker) check(err error, scriptErrorString string) error {
208 var (

Callers 1

TestScriptJsonTestsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected