Skip to content

Commit

Permalink
Exception classes in the API should extend SKException (microsoft#1112)
Browse files Browse the repository at this point in the history
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->


### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->


### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [ ] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
dsgrieve authored May 22, 2023
1 parent 6317ca1 commit bf3f403
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import javax.annotation.Nullable;

/** Kernel logic exception */
public class KernelException extends RuntimeException {
public class KernelException extends SKException {

@Nonnull private final ErrorCodes errorCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel;

public class SKException extends RuntimeException {}
import javax.annotation.Nullable;

/** Provides the base exception from which all Semantic Kernel exceptions derive. */
public class SKException extends RuntimeException {

/** Initializes a new instance of the {@code SKException} class with a default message. */
protected SKException() {
super();
}

/**
* Initializes a new instance of the {@code SKException} class with its message set to {@code
* message}.
*
* @param message A string that describes the error.
*/
protected SKException(@Nullable String message) {
super(message);
}

/**
* Initializes a new instance of the {@code SKException} class with its message set to {@code
* message}.
*
* @param message A string that describes the error.
* @param cause The exception that is the cause of the current exception.
*/
protected SKException(@Nullable String message, @Nullable Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.ai; // Copyright (c) Microsoft. All rights reserved.

import com.microsoft.semantickernel.SKException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/** AI logic exception */
public class AIException extends RuntimeException {
public class AIException extends SKException {

@Nonnull private final ErrorCodes errorCode;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.exceptions;

public class NotSupportedException extends RuntimeException {
import com.microsoft.semantickernel.SKException;

public class NotSupportedException extends SKException {
public NotSupportedException(String s) {
super(s);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.exceptions;

public class SkillsNotFoundException extends RuntimeException {}
import com.microsoft.semantickernel.SKException;

public class SkillsNotFoundException extends SKException {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.memory;

import com.microsoft.semantickernel.diagnostics.SKException;
import com.microsoft.semantickernel.SKException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.orchestration;

public class FunctionNotRegisteredException extends RuntimeException {
import com.microsoft.semantickernel.SKException;

public class FunctionNotRegisteredException extends SKException {

private static final String format =
"It does not appear this function(%s) has been registered on a kernel.%n"
+ "Register it on a kernel either by passing it to "
+ "KernelConfig.Builder().addSkill() when building the kernel, or%n"
+ "passing it to Kernel.registerSemanticFunction";

public FunctionNotRegisteredException(String name) {
super(
"It does not appear this function("
+ name
+ ") has been registered on a kernel.\n"
+ "Register it on a kernel either by passing it to"
+ " KernelConfig.Builder().addSkill() when building the kernel, or\n"
+ "passing it to Kernel.registerSemanticFunction");
super(String.format(format, name));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.skilldefinition;

public class FunctionNotFound extends RuntimeException {
import com.microsoft.semantickernel.SKException;

public class FunctionNotFound extends SKException {
public FunctionNotFound(String functionName) {
super("Could not find function: " + functionName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.templateengine;

import com.microsoft.semantickernel.diagnostics.SKException;
import com.microsoft.semantickernel.SKException;

public class TemplateException extends SKException {}

0 comments on commit bf3f403

Please sign in to comment.