Skip to content

Commit

Permalink
task(context): make Context a writable property of the client (#378)
Browse files Browse the repository at this point in the history
* task(context): make Context a writable property of the client
  • Loading branch information
rich-bugsnag committed Aug 25, 2021
1 parent 0e9d45e commit ca798bd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

### Deprecated

* `Bugsnag.SetContext(string context)` has been deprecated in favour of the new `Bugsnag.Context` property and will be removed in the next major release.

* `Configuration.Endpoint` has been deprecated in favour of the new `Configuration.Endpoints` class and will be removed in the next major release.

* `Configuration.SessionEndpoint` has been deprecated in favour of the new `Configuration.Endpoints` class and will be removed in the next major release.
Expand Down
2 changes: 1 addition & 1 deletion features/fixtures/maze_runner/Assets/Scripts/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ IEnumerator NotifyTwiceCoroutine()

IEnumerator SetManualContextReloadSceneAndNotify()
{
Bugsnag.SetContext("Manually-Set");
Bugsnag.Context = "Manually-Set";
SceneManager.LoadScene(0);
yield return new WaitForSeconds(0.5f);
Bugsnag.Notify(new System.Exception("ManualContext"));
Expand Down
20 changes: 19 additions & 1 deletion src/BugsnagUnity/Bugsnag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,32 @@ public static void SetUser(string id, string email, string name)
/// <summary>
/// Bugsnag uses the concept of contexts to help display and group your errors.
/// Contexts represent what was happening in your game at the time an error
/// occurs. By default, this will be set to be your currently active Unity Scene.
/// occurs. Unless manually set, this will be automatically set to be your currently active Unity Scene.
/// </summary>
/// <param name="context"></param>
[Obsolete("SetContext is deprecated, please use the property Bugsnag.Context instead.", false)]
public static void SetContext(string context)
{
Client.SetContext(context);
}

/// <summary>
/// Bugsnag uses the concept of contexts to help display and group your errors.
/// Contexts represent what was happening in your game at the time an error
/// occurs. Unless manually set, this will be automatically set to be your currently active Unity Scene.
/// </summary>
public static string Context
{
get
{
return Client.GetContext();
}
set
{
Client.SetContext(value);
}
}

/// <summary>
/// By default, we will automatically notify Bugsnag of any fatal errors (crashes) in your game.
/// If you want to stop this from happening, you can set the AutoNotify property to false. It
Expand Down
5 changes: 5 additions & 0 deletions src/BugsnagUnity/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ public void SetContext(string context)
NativeClient.SetContext(context);
}

public string GetContext()
{
return Configuration.Context;
}

public void SetAutoDetectErrors(bool autoDetectErrors)
{
// set the property on Configuration, as it currently controls whether C# errors are reported
Expand Down
2 changes: 2 additions & 0 deletions src/BugsnagUnity/IClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface IClient

void SetContext(string context);

string GetContext();

void SetAutoDetectErrors(bool AutoDetectErrors);

void SetAutoDetectAnrs(bool autoDetectAnrs);
Expand Down

0 comments on commit ca798bd

Please sign in to comment.