Skip to content

Commit

Permalink
log unhandled net errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Flutterish committed Feb 2, 2022
1 parent 96ddf53 commit bef36f3
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 48 deletions.
16 changes: 8 additions & 8 deletions osu.Game.Rulesets.RurusettoAddon/API/APIRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static Drawable createDefault () {
FillMode = FillMode.Fit,
Texture = logo
} );
}, () => {
}, e => {
failure?.Invoke( createDefault() );
} );
}
Expand All @@ -109,7 +109,7 @@ static Drawable createDefault () {
}
}

public void RequestDetail ( Action<RulesetDetail> success, Action? failure = null ) {
public void RequestDetail ( Action<RulesetDetail> success, Action<Exception?>? failure = null ) {
if ( Source == Source.Web && !string.IsNullOrWhiteSpace( Slug ) && API != null ) {
API.RequestRulesetDetail( Slug, success, failure );
// TODO this on failures
Expand Down Expand Up @@ -139,7 +139,7 @@ public void RequestDetail ( Action<RulesetDetail> success, Action? failure = nul
}
}

public void RequestSubpages ( Action<IEnumerable<SubpageListingEntry>> success, Action? failure = null ) {
public void RequestSubpages ( Action<IEnumerable<SubpageListingEntry>> success, Action<Exception?>? failure = null ) {
if ( Source == Source.Web && API != null && !string.IsNullOrWhiteSpace( Slug ) ) {
API.RequestSubpageListing( Slug, success, failure );
}
Expand All @@ -163,18 +163,18 @@ public void FlushSubpages () { // NOTE this doesnt refresh changlog and main
}
}

public void RequestSubpage ( string subpageSlug, Action<Subpage> success, Action? failure = null ) {
public void RequestSubpage ( string subpageSlug, Action<Subpage> success, Action<Exception?>? failure = null ) {
if ( Source == Source.Web && API != null && !string.IsNullOrWhiteSpace( Slug ) && !string.IsNullOrWhiteSpace( subpageSlug ) ) {
API.RequestSubpage( Slug, subpageSlug, success, failure );
}
else {
failure?.Invoke();
failure?.Invoke( null );
}
}

public void RequestDarkCover ( Action<Texture> success, Action? failure = null ) {
public void RequestDarkCover ( Action<Texture> success, Action<Exception?>? failure = null ) {
if ( API is null ) {
failure?.Invoke();
failure?.Invoke( null );
}
else {
RequestDetail( detail => {
Expand Down Expand Up @@ -213,7 +213,7 @@ public IEnumerable<DrawableTag> GenerateTags ( RulesetDetail detail, bool large
}

public override string ToString ()
=> $"{Name}";
=> $"{Name} [Source {Source}] [{(Source is Source.Web ? $"Slug {Slug}" : $"Path {LocalPath}")}]";
}

public enum Source {
Expand Down
13 changes: 8 additions & 5 deletions osu.Game.Rulesets.RurusettoAddon/API/APIUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static APIUser Local ( RurusettoAPI API ) {

public bool HasProfile { get; private set; }

public void RequestDetail ( Action<UserProfile> success, Action? failure = null ) {
public void RequestDetail ( Action<UserProfile> success, Action<Exception?>? failure = null ) {
if ( Source == Source.Web && API != null ) {
API.RequestUserProfile( ID, success, failure );
}
Expand All @@ -36,11 +36,11 @@ public void RequestDetail ( Action<UserProfile> success, Action? failure = null
}
}

public void RequestProfilePicture ( Action<Texture> success, Action? failure = null ) {
void requestDefault () {
public void RequestProfilePicture ( Action<Texture> success, Action<Exception?>? failure = null ) {
void requestDefault ( Exception? e = null ) {
if ( API != null ) {
API.RequestImage( StaticAPIResource.DefaultProfileImage, success, failure: () => {
failure?.Invoke();
API.RequestImage( StaticAPIResource.DefaultProfileImage, success, failure: e => {
failure?.Invoke( e );
} );
}
}
Expand All @@ -59,5 +59,8 @@ void requestDefault () {
requestDefault();
}
}

public override string ToString ()
=> Source is Source.Web ? $"User with ID = {ID}" : $"Local user";
}
}
47 changes: 35 additions & 12 deletions osu.Game.Rulesets.RurusettoAddon/API/RurusettoAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Logging;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
Expand All @@ -23,10 +24,10 @@ public RurusettoAPI () {
Address.ValueChanged += _ => FlushAllCaches();
}

private async void queue<T> ( Task<T?> task, Action<T>? success = null, Action? failure = null, Action? cancelled = null ) {
private async void queue<T> ( Task<T?> task, Action<T>? success = null, Action<Exception?>? failure = null, Action? cancelled = null ) {
if ( task.Status == TaskStatus.RanToCompletion ) {
if ( task.Result is null )
failure?.Invoke();
failure?.Invoke( task.Exception );
else
success?.Invoke( task.Result );
}
Expand All @@ -39,24 +40,34 @@ private async void queue<T> ( Task<T?> task, Action<T>? success = null, Action?
if ( address != Address.Value )
cancelled?.Invoke();
else if ( value is null )
failure?.Invoke();
failure?.Invoke( null );
else
success?.Invoke( value );
} );
}
catch ( Exception ) {
catch ( Exception e ) {
Schedule( () => {
if ( address == Address.Value )
failure?.Invoke();
failure?.Invoke( e );
else
cancelled?.Invoke();
} );
}
}
}

public void LogFailure ( string message, Exception? exception = null ) {
message = $"Unhandled Rurusetto Addon Error: `{message}` - API Address: `{Address.Value}`";
if ( exception is null )
Logger.Log( message, LoggingTarget.Network, LogLevel.Error );
else
Logger.Error( exception, message, LoggingTarget.Network );
}

private Task<IEnumerable<ListingEntry>?>? listingCache = null;
public void RequestRulesetListing ( Action<IEnumerable<ListingEntry>>? success = null, Action? failure = null, Action? cancelled = null ) {
public void RequestRulesetListing ( Action<IEnumerable<ListingEntry>>? success = null, Action<Exception?>? failure = null, Action? cancelled = null ) {
failure ??= e => LogFailure( $"Could not retrieve ruleset listing", e );

queue( listingCache ??= requestRulesetListing(), success, failure, cancelled );
}
private async Task<IEnumerable<ListingEntry>?> requestRulesetListing () {
Expand All @@ -68,7 +79,9 @@ public void FlushRulesetListingCache () {
}

private Dictionary<string, Task<RulesetDetail?>> rulesetDetailCache = new();
public void RequestRulesetDetail ( string slug, Action<RulesetDetail>? success = null, Action? failure = null ) {
public void RequestRulesetDetail ( string slug, Action<RulesetDetail>? success = null, Action<Exception?>? failure = null ) {
failure ??= e => LogFailure( $"Could not retrieve ruleset detail for {slug}", e );

if ( !rulesetDetailCache.TryGetValue( slug, out var detail ) ) {
rulesetDetailCache.Add( slug, detail = requestRulesetDetail( slug ) );
}
Expand All @@ -87,7 +100,9 @@ public void FlushRulesetDetailCache () {
}

private Dictionary<string, Task<IEnumerable<SubpageListingEntry>?>> subpageListingCache = new();
public void RequestSubpageListing ( string slug, Action<IEnumerable<SubpageListingEntry>>? success = null, Action? failure = null ) {
public void RequestSubpageListing ( string slug, Action<IEnumerable<SubpageListingEntry>>? success = null, Action<Exception?>? failure = null ) {
failure ??= e => LogFailure( $"Could not retrieve subpage listing for {slug}", e );

if ( !subpageListingCache.TryGetValue( slug, out var listing ) ) {
subpageListingCache.TryAdd( slug, listing = requestSubpageListing( slug ) );
}
Expand All @@ -106,7 +121,9 @@ public void FlushSubpageListingCache () {
}

private Dictionary<string, Task<Subpage?>> subpageCache = new();
public void RequestSubpage ( string rulesetSlug, string subpageSlug, Action<Subpage>? success = null, Action? failure = null ) {
public void RequestSubpage ( string rulesetSlug, string subpageSlug, Action<Subpage>? success = null, Action<Exception?>? failure = null ) {
failure ??= e => LogFailure( $"Could not retrieve subpage {subpageSlug} for ruleset {rulesetSlug}", e );

if ( !subpageCache.TryGetValue( $"{rulesetSlug}/{subpageSlug}", out var listing ) ) {
subpageCache.TryAdd( $"{rulesetSlug}/{subpageSlug}", listing = requestSubpage( rulesetSlug, subpageSlug ) );
}
Expand All @@ -130,7 +147,9 @@ public void FlushSubpageCache () {
}

private Dictionary<int, Task<UserProfile?>> userCache = new();
public void RequestUserProfile ( int id, Action<UserProfile>? success = null, Action? failure = null ) {
public void RequestUserProfile ( int id, Action<UserProfile>? success = null, Action<Exception?>? failure = null ) {
failure ??= e => LogFailure( $"Could not retrieve user profile with ID = {id}", e );

if ( !userCache.TryGetValue( id, out var user ) ) {
userCache.TryAdd( id, user = requestUserProfile( id ) );
}
Expand All @@ -149,7 +168,9 @@ public void FlushUserProfileCache () {
}

private Dictionary<string, Task<Texture?>> mediaTextureCache = new();
public void RequestImage ( string uri, Action<Texture>? success = null, Action? failure = null ) {
public void RequestImage ( string uri, Action<Texture>? success = null, Action<Exception?>? failure = null ) {
failure ??= e => LogFailure( $"Could not retrieve image at `{uri}`", e );

if ( !mediaTextureCache.TryGetValue( uri, out var task ) ) {
mediaTextureCache.TryAdd( uri, task = requestImage( uri ) );
}
Expand All @@ -176,7 +197,9 @@ public void FlushImageCache () {
mediaTextureCache.Clear();
}

public void RequestImage ( StaticAPIResource resource, Action<Texture>? success = null, Action? failure = null ) {
public void RequestImage ( StaticAPIResource resource, Action<Texture>? success = null, Action<Exception?>? failure = null ) {
failure ??= e => LogFailure( $"Could not retrieve static resource {resource} at {resource.GetURI()}", e );

RequestImage( resource.GetURI(), success, failure );
}
public void FlushImageCache ( StaticAPIResource resource ) {
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.RurusettoAddon/RulesetDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void CheckAvailability ( APIRuleset ruleset ) {
availability.Value |= Availability.AvailableOnline;
else
availability.Value |= Availability.NotAvailableOnline;
}, failure: () => {
}, failure: _ => {
availability.Value |= Availability.NotAvailableOnline;
} );

Expand Down Expand Up @@ -124,10 +124,10 @@ private void createDownloadTask ( APIRuleset ruleset, TaskType type, DownloadSta
tasks[ ruleset ] = task with { Source = filename };
GetStateBindable( ruleset ).Value = finishedState;

}, failure: () => {
}, failure: e => {
if ( wasTaskCancelled( ruleset, task ) ) return;
tasks.Remove( ruleset );
// TODO report this
API.LogFailure( $"Download manager could not retrieve detail for {ruleset}", e );
} );
}

Expand Down
8 changes: 6 additions & 2 deletions osu.Game.Rulesets.RurusettoAddon/RulesetIdentityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ private async Task<RulesetIdentities> getIdentities () {
listing = result;
hasWeb = true;
task.SetResult();
}, failure: () => task.SetResult(), /* TODO report this */
cancelled: () => task.SetResult()

}, failure: e => {
API.LogFailure( $"Identity manager could not retrieve ruleset listing", e );
task.SetResult();
},
cancelled: () => task.SetResult()
);

await task.Task;
Expand Down
16 changes: 8 additions & 8 deletions osu.Game.Rulesets.RurusettoAddon/UI/Info/InfoTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ protected override void LoadContent () {
if ( !isCoverLoaded ) {
cover.Texture = texture;
}
}, failure: () => { /* TODO report this */ } );
} );

ruleset.RequestDarkCover( texture => {
isCoverLoaded = true;
cover.Texture = texture;
}, failure: () => { /* TODO report this */ } );
} );

loadHeader();
}
Expand Down Expand Up @@ -236,7 +236,7 @@ void addDefaultSubpages () {
subpageTabControl.Current.Value = main;
Overlay.FinishLoadiong( this );

}, failure: () => {
}, failure: e => {
addDefaultSubpages();

info.Add( new RequestFailedDrawable {
Expand Down Expand Up @@ -280,7 +280,7 @@ void loadCurrentPage () {
markdown.Text = subpage.Content ?? "";
Overlay.FinishLoadiong( this );

}, failure: () => {
}, failure: e => {
content.Insert( -1, new Container {
Padding = new MarginPadding { Horizontal = -32 },
AutoSizeAxes = Axes.Y,
Expand Down Expand Up @@ -325,8 +325,8 @@ void loadMainPage () {
}, true );
Overlay.FinishLoadiong( this );

}, failure: () => {
// TODO report this
}, failure: e => {
API.LogFailure( $"Could not retrieve detail for {ruleset}", e );
Overlay.FinishLoadiong( this );
} );
}
Expand Down Expand Up @@ -371,8 +371,8 @@ void loadHeader () {
} );
Overlay.FinishLoadiong( this );

}, failure: () => {
// TODO report this
}, failure: e => {
API.LogFailure( $"Could not retrieve detail for {ruleset}", e );
Overlay.FinishLoadiong( this );
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ private void load ( OverlayColourProvider colours, LocalisationManager localisat
if ( !isCoverLoaded ) {
cover.Texture = texture;
}
}, failure: () => { /* TODO report this */ } );
} );

Ruleset.RequestDarkCover( texture => {
cover.Texture = texture;
isCoverLoaded = true;
}, failure: () => { /* TODO report this */ } );
} );

Ruleset.RequestDetail( detail => {
Tags.AddRange( Ruleset.GenerateTags( detail ) );
}, failure: () => { /* TODO report this */ } );
} );

Add( new HoverClickSounds() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public RurusettoOverlayHeader () {

ruleset.RequestDarkCover( texture => {
background.SetCover( texture );
}, failure: () => { /* TODO report this */ } );
} );
}
else if ( v.NewValue is APIUser user ) {
TabControl.AddItem( selectedTab = $"user" );
Expand All @@ -41,7 +41,7 @@ public RurusettoOverlayHeader () {
TabControl.AddItem( selectedTab = $"{detail.Username} (user)" );
Current.Value = selectedTab;
}
}, failure: () => { /* TODO report this */ } );
} );
}
else {
Current.Value = listingText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected override void LoadComplete () {
this.profile = profile;
usernameText = profile.Username ?? "";
username.Text = profile.Username ?? Localisation.Strings.UserUnknown;
}, failure: () => { /* TODO report this */ } );
} );

user.RequestProfilePicture( texture => {
pfp.Texture = texture;
Expand Down
6 changes: 2 additions & 4 deletions osu.Game.Rulesets.RurusettoAddon/UI/Users/UserTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ protected override void LoadContent () {
Add( new DrawableRurusettoUser( User, false ) { Height = 80 } );

User.RequestDetail( profile => {

OnContentLoaded();
}, failure: () => {
// TODO report this

}, failure: e => {
API.LogFailure( $"Could not retrieve profile for {User}", e );
OnContentLoaded();
} );
}
Expand Down

0 comments on commit bef36f3

Please sign in to comment.