Skip to content

Commit c17528a

Browse files
committed
ST6RI-823 Minor enhancements to the registrator workflow
- Added error handling for the command registrator interface - Added Javadoc to the registrator to clarify the expected contract of implementors
1 parent 4e0c3e8 commit c17528a

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/IMagicCommandRegistrator.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
* SysML 2 Pilot Implementation
33
* Copyright (c) 2025 Model Driven Solutions, Inc.
4-
*
4+
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
77
* the Free Software Foundation, either version 3 of the License, or
@@ -16,16 +16,31 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*
1818
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19-
*
19+
*
2020
* Contributors:
2121
* Zoltan Ujhelyi, MDS
22-
*
22+
*
2323
*****************************************************************************/
2424
package org.omg.sysml.jupyter.kernel;
2525

26+
import org.omg.sysml.interactive.SysMLInteractiveHelp;
27+
2628
import io.github.spencerpark.jupyter.kernel.magic.registry.Magics;
2729

2830
public interface IMagicCommandRegistrator {
2931

32+
/**
33+
* Implementors of this method are free to register their extra commands to the
34+
* Jupyter kernel. This method is called when the Jupyter environment is
35+
* initialized and it assumed the registration code will run quickly and without
36+
* exceptions. If the registrator cannot run successfully, it should not
37+
* register anything instead of throwing an exception.
38+
* </p>
39+
* Implementors are recommended to use the register methods of the {@link Magics}
40+
* class. Help is managed by the {@link SysMLInteractiveHelp} class.
41+
*
42+
* @see Magics#registerMagics(Class)
43+
* @see SysMLInteractiveHelp#registerHelpString(String, String, String)
44+
*/
3045
void registerMagicCommand(Magics magics);
3146
}

org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ public SysMLKernel() {
8585
this.magics.registerMagics(Load.class);
8686
this.magics.registerMagics(ApiBasePath.class);
8787

88-
ServiceLoader.load(IMagicCommandRegistrator.class).forEach(reg -> reg.registerMagicCommand(this.magics));
88+
ServiceLoader.load(IMagicCommandRegistrator.class).forEach(reg -> {
89+
try {
90+
reg.registerMagicCommand(this.magics);
91+
} catch (Exception e) {
92+
// Given there is no available logging mechanism and an exception thrown by the
93+
// registrator would cause the Jupyter kernel not to start up correctly, errors
94+
// are logged to the standard err output, but otherwise ignored.
95+
System.err.printf("Error while running the command registrator %s: %s", reg.getClass().getTypeName(),
96+
e.getMessage());
97+
}
98+
});
8999

90100
this.magicParser = new MyMagicParser();
91101
}

0 commit comments

Comments
 (0)