From b2cdd5d848d943ac23f4e2535599d5707f71682c Mon Sep 17 00:00:00 2001 From: simson <526422051@qq.com> Date: Mon, 27 Jul 2020 15:42:41 +0800 Subject: [PATCH] Fix the difference of Error type between graph&pynative mode --- mindspore/ccsrc/frontend/operator/prim_structures.cc | 5 +++-- tests/ut/python/ops/test_tuple_slice.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/frontend/operator/prim_structures.cc b/mindspore/ccsrc/frontend/operator/prim_structures.cc index 1d1e6376d0f..cc53f9aa228 100644 --- a/mindspore/ccsrc/frontend/operator/prim_structures.cc +++ b/mindspore/ccsrc/frontend/operator/prim_structures.cc @@ -150,11 +150,12 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr for (size_t index = 0; index < args_size; index++) { MS_EXCEPTION_IF_NULL(args_spec_list[index]); if (!args_spec_list[index]->isa() && !args_spec_list[index]->isa()) { - MS_LOG(EXCEPTION) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone."; + MS_EXCEPTION(TypeError) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone."; } if (args_spec_list[index]->isa() && !dyn_cast(args_spec_list[index])->BuildValue()->isa()) { - MS_LOG(EXCEPTION) << "MakeSlice eval " << index << " parameter is an AbstractScalar, but is not an int32 number."; + MS_EXCEPTION(TypeError) << "MakeSlice eval " << index + << " parameter is an AbstractScalar, but is not an int32 number."; } } // Slice: start, end, step diff --git a/tests/ut/python/ops/test_tuple_slice.py b/tests/ut/python/ops/test_tuple_slice.py index 1475c177f4a..bfa573b8dfe 100644 --- a/tests/ut/python/ops/test_tuple_slice.py +++ b/tests/ut/python/ops/test_tuple_slice.py @@ -114,13 +114,13 @@ test_cases = [ test_cases_for_verify_exception = [ ('SliceStartCross', { - 'block': (NetWork_3(), {'exception': RuntimeError}), + 'block': (NetWork_3(), {'exception': TypeError}), 'desc_inputs': [Tensor(np.ones([2, 3, 4], np.int32)), Tensor(np.zeros([2, 3, 4], np.int32)), Tensor(np.ones([2, 3, 4], np.int32))], }), ('SliceStepZero', { - 'block': (NetWork_3(), {'exception': RuntimeError}), + 'block': (NetWork_3(), {'exception': TypeError}), 'desc_inputs': [Tensor(np.ones([2, 3, 4], np.int32)), Tensor(np.zeros([2, 3, 4], np.int32)), Tensor(np.ones([2, 3, 4], np.int32))],