@@ -25,8 +25,12 @@ module.exports = {
25
25
example : '==='
26
26
} ,
27
27
28
- meta :
29
- require ( '../constants/meta.input' )
28
+ meta : {
29
+ friendlyName : 'Meta (custom)' ,
30
+ description : 'Additional stuff to pass to the driver.' ,
31
+ extendedDescription : 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.' ,
32
+ example : '==='
33
+ }
30
34
31
35
} ,
32
36
@@ -47,53 +51,54 @@ module.exports = {
47
51
} ,
48
52
49
53
50
- fn : function ( inputs , exits ) {
51
- var util = require ( 'util' ) ;
52
-
53
-
54
+ fn : function parseNativeQueryError ( inputs , exits ) {
55
+ var _ = require ( 'lodash' ) ;
54
56
55
57
// Quick reference of hand-tested errors:
56
58
57
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
59
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
58
60
// `code` : 'ER_PARSE_ERROR'
59
61
// `errno` : 1064
60
62
// `sqlState` : '42000'
61
63
// `index` : 0
62
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
64
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
63
65
64
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
66
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
65
67
// `code` : 'ER_NO_SUCH_TABLE'
66
68
// `errno` : 1146
67
69
// `sqlState` : '42S02'
68
70
// `index` : 0
69
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
71
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
70
72
71
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
73
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
72
74
// `code` : 'ER_DUP_ENTRY'
73
75
// `errno` : 1062
74
76
// `sqlState` : '23000'
75
77
// `index` : 0
76
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
77
-
78
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
78
79
79
80
80
81
// Local variable (`err`) for convenience.
81
82
var err = inputs . nativeQueryError ;
82
83
83
84
// `footprint` is primarily what will be returned by this machine.
84
- var footprint ;
85
-
86
- // `meta` will also be returned if it is set below.
87
- var meta ;
85
+ // For miscellaneous errors which are not explicitly in the
86
+ // spec, return the catchall footprint. Drivers should not
87
+ // add their own additional footprints-- instead, if they want
88
+ // to allow for easily identifying a particular error, the
89
+ // `catchall` footprint should still be used; but additional
90
+ // information sent back in `meta`.
91
+ var footprint = { identity : 'catchall' } ;
88
92
89
93
90
94
// If the incoming native query error is not an object, or it is
91
95
// missing a `code` property, then we'll go ahead and bail out w/
92
96
// the "catchall" footprint to avoid continually doing these basic
93
97
// checks in the more detailed error negotiation below.
94
- if ( ! util . isObject ( err ) || ! err . code ) {
98
+ if ( ! _ . isObject ( err ) || ! err . code ) {
95
99
return exits . success ( {
96
- footprint : { identity : 'catchall' }
100
+ footprint : footprint ,
101
+ meta : inputs . meta
97
102
} ) ;
98
103
}
99
104
@@ -106,7 +111,7 @@ module.exports = {
106
111
// > that is, only one of them should be run.
107
112
108
113
109
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
114
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
110
115
// `code` : 'ER_DUP_ENTRY'
111
116
// `errno` : 1062
112
117
// `sqlState` : '23000'
@@ -116,7 +121,7 @@ module.exports = {
116
121
// Waterline driver spec. If additional information
117
122
// is needed in userland beyond what is guaranteed in
118
123
// the spec, then you should take advantage of `meta`.
119
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
124
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
120
125
if ( err . code === 'ER_DUP_ENTRY' ) {
121
126
// Negotiate `notUnique` error footprint.
122
127
footprint = {
@@ -126,16 +131,16 @@ module.exports = {
126
131
// Now build our footprint's `keys` property by manually parsing
127
132
// the MySQL error message and extracting the relevant bits.
128
133
// (See also: https://github.com/balderdashy/sails-mysql/blob/2c414f1191c3595df2cea8e40259811eb3ca05f9/lib/adapter.js#L1223)
129
- if ( util . isString ( err . message ) ) {
134
+ if ( _ . isString ( err . message ) ) {
130
135
var matches = err . message . match ( / D u p l i c a t e e n t r y ' .* ' f o r k e y ' ( .* ?) ' $ / ) ;
131
- if ( matches && matches . length > 0 ) {
136
+ if ( matches && matches . length > 0 ) {
132
137
footprint . keys . push ( matches [ 1 ] ) ;
133
138
}
134
139
}
135
140
}
136
141
137
142
138
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
143
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
139
144
// `code` : 'ER_NO_SUCH_TABLE'
140
145
// `errno` : 1146
141
146
// `sqlState` : '42S02'
@@ -145,15 +150,15 @@ module.exports = {
145
150
// reference. If this driver wants to move ahead of
146
151
// the core Waterline/machine spec, this can be handled
147
152
// using the `catchall` footprint + `meta`.
148
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
153
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
149
154
// else if ( ... ){
150
155
// footprint = { identity: 'catchall' };
151
156
// // e.g.
152
157
// meta = { problem: 'noSuchTable', foo: ..., bar: ... };
153
158
// }
154
159
155
160
156
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
161
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
157
162
// `code` : 'ER_PARSE_ERROR'
158
163
// `errno` : 1064
159
164
// `sqlState` : '42000'
@@ -163,38 +168,21 @@ module.exports = {
163
168
// reference. If this driver wants to move ahead of
164
169
// the core Waterline/machine spec, this can be handled
165
170
// using the `catchall` footprint + `meta`.
166
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
171
+ // --o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
167
172
// else if ( ... ){
168
173
// footprint = { identity: 'catchall' };
169
174
// // e.g.
170
175
// meta = { problem: 'couldNotParse', foo: ..., bar: ... };
171
176
// }
172
177
173
178
174
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
175
- // ??????
176
- //
177
- // For miscellaneous errors which are not explicitly in the
178
- // spec, return the catchall footprint. Drivers should not
179
- // add their own additional footprints-- instead, if they want
180
- // to allow for easily identifying a particular error, the
181
- // `catchall` footprint should still be used; but additional
182
- // information sent back in `meta`.
183
- //
184
- //--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o-<>
185
- else {
186
- footprint = { identity : 'catchall' } ;
187
- }
188
-
189
-
190
-
191
179
// Finally, return the normalized footprint.
192
180
//
193
181
// (as well as any additional metadata that was stuffed
194
182
// into `meta` above)
195
183
return exits . success ( {
196
184
footprint : footprint ,
197
- meta : meta
185
+ meta : inputs . meta
198
186
} ) ;
199
187
}
200
188
0 commit comments