Skip to content

Commit f762505

Browse files
rushmoremmhallin
authored andcommitted
Expose executor.location(), rename executor.push_error() to
`executor.push_error_at()` and add a new `executor.push_error()`
1 parent b3ea59c commit f762505

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

juniper/src/executor.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
288288
match self.resolve(info, value) {
289289
Ok(v) => v,
290290
Err(e) => {
291-
let position = self.field_path.location().clone();
292-
self.push_error(e, position);
291+
self.push_error(e);
293292
Value::null()
294293
}
295294
}
@@ -355,8 +354,19 @@ impl<'a, CtxT> Executor<'a, CtxT> {
355354
self.fragments.get(name).map(|f| *f)
356355
}
357356

358-
/// Add an error to the execution engine
359-
pub fn push_error(&self, error: FieldError, location: SourcePosition) {
357+
/// The current location of the executor
358+
pub fn location(&self) -> &SourcePosition {
359+
self.field_path.location()
360+
}
361+
362+
/// Add an error to the execution engine at the current executor location
363+
pub fn push_error(&self, error: FieldError) {
364+
let location = self.location().clone();
365+
self.push_error_at(error, location);
366+
}
367+
368+
/// Add an error to the execution engine at a specific location
369+
pub fn push_error_at(&self, error: FieldError, location: SourcePosition) {
360370
let mut path = Vec::new();
361371
self.field_path.construct_path(&mut path);
362372

juniper/src/types/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn resolve_selection_set_into<T, CtxT>(
390390
match field_result {
391391
Ok(v) => merge_key_into(result, response_name, v),
392392
Err(e) => {
393-
sub_exec.push_error(e, start_pos.clone());
393+
sub_exec.push_error_at(e, start_pos.clone());
394394
result.insert((*response_name).to_owned(), Value::null());
395395
}
396396
}
@@ -439,7 +439,7 @@ fn resolve_selection_set_into<T, CtxT>(
439439
result.insert(k, v);
440440
}
441441
} else if let Err(e) = sub_result {
442-
sub_exec.push_error(e, start_pos.clone());
442+
sub_exec.push_error_at(e, start_pos.clone());
443443
}
444444
} else {
445445
resolve_selection_set_into(

0 commit comments

Comments
 (0)