Skip to content

Commit

Permalink
fix crash on launch due to default workspace not set in DB (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogchap authored Nov 25, 2020
1 parent 4a4fcac commit 1fc3887
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Crash on launch due to poor handling of the default workspace for first time user

## [v0.3.1] - 2020-11-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/WorkspaceList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<span class="box"/>
{/if}
</td>
<td class:selected={wksp.id === current.id}>{wksp.addr}</td>
<td class:selected={wksp.id === current.id}>{!wksp.addr && wksp.id === "wksp_default" ? "default workspace" : wksp.addr}</td>
<td>
{#if wksp.id !== "wksp_default"}
<CrossButton on:click={() => onDeleteClicked(wksp)} color={isWin ? "#bf616a" : "var(--red-color)"} />
Expand Down
29 changes: 22 additions & 7 deletions internal/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,30 @@ func (a *api) getCurrentState() *workspaceState {

// GetWorkspaceOptions gets the workspace options from the store
func (a *api) GetWorkspaceOptions() (*options, error) {
val, err := a.store.get([]byte(a.state.CurrentID))
if err != nil {
wo := &options{
ID: a.state.CurrentID,
}

val, err := a.store.get([]byte(wo.ID))
if err != nil && err != errKeyNotFound {
return nil, err
}

var opts *options
if len(val) == 0 {
return wo, nil
}

dec := gob.NewDecoder(bytes.NewBuffer(val))
err = dec.Decode(&opts)
err = dec.Decode(wo)
if err != nil {
return nil, err
}

if opts.ID == "" {
opts.ID = defaultWorkspaceKey
if wo.ID == "" {
wo.ID = defaultWorkspaceKey
}

return opts, err
return wo, nil
}

// GetReflectMetadata gets the reflection metadata from the store by addr
Expand Down Expand Up @@ -211,6 +221,7 @@ func (a *api) ListWorkspaces() ([]options, error) {
return nil, err
}
var opts []options
hasDefault := false
for _, val := range items {
opt := options{}
dec := gob.NewDecoder(bytes.NewBuffer(val))
Expand All @@ -219,12 +230,16 @@ func (a *api) ListWorkspaces() ([]options, error) {
}
// opts.ID was added in v0.3.0 so need to double check
if opt.ID == defaultWorkspaceKey || opt.ID == "" {
hasDefault = true
opt.ID = defaultWorkspaceKey
opts = append([]options{opt}, opts...)
continue
}
opts = append(opts, opt)
}
if !hasDefault {
opts = append([]options{options{ID: defaultWorkspaceKey}}, opts...)
}
return opts, nil
}

Expand Down

0 comments on commit 1fc3887

Please sign in to comment.