From 3e302ac88a29f5d2b73d637557b07cb6daca35ca Mon Sep 17 00:00:00 2001
From: Georgy Moshkin <gmoshkin@picodata.io>
Date: Fri, 17 Feb 2023 11:35:24 +0300
Subject: [PATCH] fix(migration): don't ignore migration apply errors

---
 src/traft/rpc/migration.rs | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/traft/rpc/migration.rs b/src/traft/rpc/migration.rs
index e46fe8a105..e8712b5780 100644
--- a/src/traft/rpc/migration.rs
+++ b/src/traft/rpc/migration.rs
@@ -11,15 +11,21 @@ pub mod apply {
 
             let storage = &node.storage;
 
-            match storage.migrations.get(req.migration_id)? {
-                Some(migration) => {
-                    match lua_state().exec_with("box.execute(...)", migration.body) {
-                        Ok(_) => Ok(Response{}),
-                        Err(e) => Err(LuaError::from(e).into()),
-                    }
-                }
-                None => Err(Error::other(format!("Migration {0} not found", req.migration_id))),
-            }
+            let Some(migration) = storage.migrations.get(req.migration_id)? else {
+                return Err(Error::other(format!("migration {0} not found", req.migration_id)));
+            };
+
+            lua_state()
+                .exec_with(
+                    "local ok, err = box.execute(...)
+                    if not ok then
+                        box.error(err)
+                    end",
+                    migration.body,
+                )
+                .map_err(LuaError::from)?;
+
+            Ok(Response {})
         }
 
         pub struct Request {
-- 
GitLab