Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#584 Add root config origin to exception #585

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/src/main/java/com/typesafe/config/ConfigException.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.lang.reflect.Field;

import com.typesafe.config.impl.ConfigImplUtil;
import com.typesafe.config.impl.Path;

/**
* All exceptions thrown by the library are subclasses of
Expand Down Expand Up @@ -126,6 +127,10 @@ public Missing(String path, Throwable cause) {
cause);
}

public Missing(ConfigOrigin origin, Path path) {
this(origin, "No configuration setting found for key '" + path.render() + "'");
}

public Missing(String path) {
this(path, null);
}
Expand Down
4 changes: 2 additions & 2 deletions config/src/main/java/com/typesafe/config/impl/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.typesafe.config.ConfigException;

final class Path {
public final class Path {

final private String first;
final private Path remainder;
Expand Down Expand Up @@ -216,7 +216,7 @@ public String toString() {
* toString() is a debugging-oriented version while this is an
* error-message-oriented human-readable one.
*/
String render() {
public String render() {
StringBuilder sb = new StringBuilder();
appendToStringBuilder(sb);
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static private AbstractConfigValue findKeyOrNull(AbstractConfigObject self, Stri
ConfigValueType expected, Path originalPath) {
AbstractConfigValue v = self.peekAssumingResolved(key, originalPath);
if (v == null)
throw new ConfigException.Missing(originalPath.render());
throw new ConfigException.Missing(self.origin(), originalPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather keep the Path.render() here instead of making Path public. Otherwise the PR lgtm, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used Path as argument because constructor with string argument ar used in Null exception


if (expected != null)
v = DefaultTransformer.transform(v, expected);
Expand Down