Skip to content

Commit

Permalink
feat: add a flag whether to ignore the CLI errors during Android symb…
Browse files Browse the repository at this point in the history
…ol upload (#1687)
  • Loading branch information
munkiki7 authored Jun 10, 2024
1 parent 53a2418 commit 60065fb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Added an `IgnoreCliErrors` to the Sentry-CLI options, allowing you to ignore errors during symbol and mapping upload ([#1687](https://github.com/getsentry/sentry-unity/pull/1687))

### Dependencies

- Bump Cocoa SDK from v8.27.0 to v8.28.0 ([#1685](https://github.com/getsentry/sentry-unity/pull/1685))
Expand Down
16 changes: 12 additions & 4 deletions src/Sentry.Unity.Editor/Android/DebugSymbolUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class DebugSymbolUpload
private readonly string _gradleScriptPath;
private readonly bool _isExporting;
private readonly bool _isMinifyEnabled;
private readonly bool _ignoreCliErrors;

private readonly SentryCliOptions? _cliOptions;
private readonly List<string> _symbolUploadPaths;
Expand Down Expand Up @@ -56,7 +57,10 @@ private string _symbolUploadTaskFormat
stringBuilder.AppendLine(" println 'Uploading symbols to Sentry. You can find the full log in ./Logs/sentry-symbols-upload.log (the file content may not be strictly sequential because it\\'s a merge of two streams).'");
stringBuilder.AppendLine($" def logFilePath = '{logsDir}/{SymbolUploadLogName}'");
stringBuilder.AppendLine(" def sentryLogFile = new FileOutputStream(logFilePath)");
stringBuilder.AppendLine(" try {");
if (_ignoreCliErrors)
{
stringBuilder.AppendLine(" try {");
}
}

stringBuilder.AppendLine(" exec {");
Expand All @@ -70,7 +74,7 @@ private string _symbolUploadTaskFormat
}

stringBuilder.AppendLine(" }");
if (!_isExporting)
if (!_isExporting && _ignoreCliErrors)
{
stringBuilder.AppendLine(" } catch (exception) {");
stringBuilder.AppendLine(" def file = new File(logFilePath)");
Expand Down Expand Up @@ -103,6 +107,7 @@ public DebugSymbolUpload(IDiagnosticLogger logger,
_gradleScriptPath = Path.Combine(_gradleProjectPath, "launcher/build.gradle");
_isExporting = isExporting;
_isMinifyEnabled = minifyEnabled;
_ignoreCliErrors = cliOptions != null && cliOptions.IgnoreCliErrors;

_cliOptions = cliOptions;
_symbolUploadPaths = GetSymbolUploadPaths(application);
Expand Down Expand Up @@ -251,7 +256,10 @@ private void CheckMapping(StringBuilder stringBuilder)
Directory.CreateDirectory(logsDir);
stringBuilder.AppendLine($" def mappingLogFilePath = '{logsDir}/{MappingUploadLogName}'");
stringBuilder.AppendLine($" def mappingLogFile = new FileOutputStream(mappingLogFilePath)");
stringBuilder.AppendLine(" try {");
if (!_isExporting && _ignoreCliErrors)
{
stringBuilder.AppendLine(" try {");
}
}
stringBuilder.AppendLine(" exec {");
stringBuilder.AppendLine(" environment 'SENTRY_PROPERTIES', './sentry.properties'");
Expand All @@ -264,7 +272,7 @@ private void CheckMapping(StringBuilder stringBuilder)
}

stringBuilder.AppendLine(" }");
if (!_isExporting)
if (!_isExporting && _ignoreCliErrors)
{
stringBuilder.AppendLine(" } catch (exception) {");
stringBuilder.AppendLine(" def file = new File(mappingLogFilePath)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ internal static void Display(SentryCliOptions cliOptions)
new GUIContent("Upload Sources", "Whether your source code should be uploaded to Sentry, so the stack trace in Sentry has the relevant code next to it."),
cliOptions.UploadSources);

cliOptions.IgnoreCliErrors = EditorGUILayout.Toggle(
new GUIContent("Ignore CLI Errors", "Whether to ignore the Sentry CLI errors during the build. If this is ON, the errors will be logged, but the build will succeed."),
cliOptions.IgnoreCliErrors);

EditorGUILayout.EndToggleGroup();

cliOptions.Auth = EditorGUILayout.TextField(
Expand Down
1 change: 1 addition & 0 deletions src/Sentry.Unity/SentryCliOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public sealed class SentryCliOptions : ScriptableObject
[field: SerializeField] public string? Auth { get; set; }
[field: SerializeField] public string? Organization { get; set; }
[field: SerializeField] public string? Project { get; set; }
[field: SerializeField] public bool IgnoreCliErrors { get; set; } = false;

internal static string GetConfigPath(string? notDefaultConfigName = null)
=> $"Assets/Plugins/Sentry/{notDefaultConfigName ?? ConfigName}.asset";
Expand Down
25 changes: 18 additions & 7 deletions test/Sentry.Unity.Editor.Tests/Android/DebugSymbolUploadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Fixture

public bool IsExporting { get; set; }
public bool IsMinifyEnabled { get; set; }
public bool IgnoreCliErrors { get; set; }
public TestApplication Application { get; set; }

public Fixture()
Expand All @@ -39,7 +40,7 @@ public Fixture()

internal DebugSymbolUpload GetSut() => new(
new UnityLogger(new SentryOptions(), UnityTestLogger),
new SentryCliOptions() { UploadSources = true },
new SentryCliOptions() { UploadSources = true, IgnoreCliErrors = IgnoreCliErrors },
UnityProjectPath,
GradleProjectPath,
IsExporting,
Expand Down Expand Up @@ -122,14 +123,19 @@ public void AppendUploadToGradleFile_BuildGradleFileDoesNotExist_ThrowsFileNotFo
}

[Test]
[TestCase(false, false)]
[TestCase(true, false)]
[TestCase(true, true)]
[TestCase(false, true)]
public void AppendUploadToGradleFile_AllRequirementsMet_AppendsUploadTask(bool isExporting, bool addMapping)
[TestCase(false, false, false)]
[TestCase(true, false, false)]
[TestCase(true, true, false)]
[TestCase(false, true, false)]
[TestCase(false, false, true)]
[TestCase(true, false, true)]
[TestCase(true, true, true)]
[TestCase(false, true, true)]
public void AppendUploadToGradleFile_AllRequirementsMet_AppendsUploadTask(bool isExporting, bool addMapping, bool ignoreCliErrors)
{
_fixture.IsExporting = isExporting;
_fixture.IsMinifyEnabled = addMapping;
_fixture.IgnoreCliErrors = ignoreCliErrors;
var sut = _fixture.GetSut();

sut.AppendUploadToGradleFile(_fixture.SentryCliPath);
Expand All @@ -147,10 +153,15 @@ public void AppendUploadToGradleFile_AllRequirementsMet_AppendsUploadTask(bool i

if (!isExporting)
{
keywords.Add("try {");
keywords.Add("logFilePath");
}

if (!isExporting && ignoreCliErrors)
{
keywords.Add("try {");
keywords.Add("} catch");
}

if (addMapping)
{
keywords.Add("args = ['upload-proguard'");
Expand Down

0 comments on commit 60065fb

Please sign in to comment.