Skip to content

Commit

Permalink
(#85) Publish VSCode extension 0.1.6 - Various UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed May 18, 2024
1 parent 409c369 commit 852039d
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 203 deletions.
2 changes: 1 addition & 1 deletion rust/suibase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = ["crates/suibase-daemon",
[workspace.package]
# Bump 'version' for the daemon to self-restart after an update.
# (this is not the Suibase package version, it is specifically for the Rust crates).
version = "0.0.6"
version = "0.0.7"
edition = "2021"

[workspace.dependencies]
Expand Down
6 changes: 4 additions & 2 deletions rust/suibase/crates/common/src/workers/shell_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ impl ShellWorker {
Ok(output) => {
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
let resp = format!("{}{}", stdout, stderr);
let resp = format!("{}{}", stderr, stdout); // Put error first for easier detection.
// Remove leading/trailing whitespaces (including empty lines).
let resp = resp.trim().to_string();
if output.status.success() && stderr.is_empty() {
resp
} else {
Expand All @@ -110,7 +112,7 @@ impl ShellWorker {
"Error: do_exec({:?}, {:?}) error 1: {}",
msg.workdir_idx, cmd, e
);
log::error!("{}", error_msg);
//log::error!("{}", error_msg);
error_msg
}
}
Expand Down
58 changes: 46 additions & 12 deletions rust/suibase/crates/suibase-daemon/src/api/impl_general_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,57 @@ impl GeneralApiImpl {
) -> bool {
// First line is two words, first should match the workdir name followed by the status word.
// If the workdir name does not match, then the resp.status is set to "DOWN" else the status word is stores in resp.status.

// Success if at least first line parsed (may extend to other lines later...) and other
// lines are not errors.
/*log::info!(
"{} convert_status_cmd_resp_to_status_response: cmd_response=[{}]",
workdir_name,
cmd_response
);*/
let mut first_line_parsed = false;

// Iterate every lines of cmd.
let mut line_number = 0;
let mut error_detected = false;

let cmd = Self::remove_ascii_color_code(&cmd_response);
for line in cmd.lines() {
if line.trim_start().starts_with("Error:") {
return false;
let line = line.trim();
// Ignore empty lines or "---" divider.
if line.is_empty() || line.starts_with("---") {
continue;
}

// Ignore lines starting with a "---" divider.
if line.trim_start().starts_with("---") {
continue;
if line.starts_with("Error:") {
error_detected = true;
}

line_number += 1;

// Detect into the first two lines for a hint of a problem.
if line_number <= 2 {
let line_lc = line.to_lowercase();
// Detect Suibase not installed.
if line_lc.contains("not initialized")
|| line_lc.contains("not found")
|| line_lc.contains("no such")
{
resp.status = Some("DISABLED".to_string());
let status_info = format!("{0} not initialized. Do '{0} start'", workdir_name);
resp.status_info = Some(status_info);
return false;
}
}

if error_detected {
if line_number == 2 {
// Error detected but not sure what the problem is.
resp.status = Some("DOWN".to_string());
resp.status_info = Some(format!("Error detected [{}]", cmd_response));
log::error!("Workdir status error detected [{}]", cmd_response);
return false;
}
continue;
}

// Split the line into words.
let mut words = line.split_whitespace();

Expand Down Expand Up @@ -343,11 +373,12 @@ impl GeneralApiImpl {

// Do not assumes that if shell_exec returns OK that the command was successful.
// Parse the command response to figure out if really successful.
let is_successful =
resp.status = None;
let _is_successful =
self.convert_status_cmd_resp_to_status_response(cmd_resp, workdir, &mut resp);

if !is_successful {
// Command was not successful, make 100% sure the status is DOWN.
// Default to DOWN if could not identify the status.
if resp.status.is_none() {
resp.status = Some("DOWN".to_string());
}

Expand Down Expand Up @@ -618,7 +649,10 @@ impl GeneralApiServer for GeneralApiImpl {
.await
{
Ok(cmd_resp) => cmd_resp,
Err(e) => format!("Error: {e}"),
Err(e) => {
log::error!("Error: {e}");
format!("Error: {e}")
}
};

// Do not assumes that if shell_exec returns OK that the command was successful.
Expand Down
33 changes: 33 additions & 0 deletions scripts/common/__suibase-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,40 @@ start_suibase_daemon_as_needed() {
update_SUIBASE_DAEMON_VERSION_SOURCE_CODE
#echo SUIBASE_DAEMON_VERSION_INSTALLED="$SUIBASE_DAEMON_VERSION_INSTALLED"
#echo SUIBASE_DAEMON_VERSION_SOURCE_CODE="$SUIBASE_DAEMON_VERSION_SOURCE_CODE"
local _PERFORM_UPGRADE=false

if need_suibase_daemon_upgrade; then
_PERFORM_UPGRADE=true

# To try to minimize race conditions, wait until a concurrent script
# is done doing the same. Not perfect... good enough.
#
# This also hint the VSCode extension to step back from using the
# backend while this is on-going.
local _CHECK_IF_NEEDED_AGAIN=false
local _FIRST_ITERATION=true
while [ -f /tmp/.suibase/suibase-daemon-upgrading ]; do
if $_FIRST_ITERATION; then
echo "Waiting for concurrent script to finish upgrading suibase daemon..."
_FIRST_ITERATION=false
fi
sleep 1
_PERFORM_UPGRADE=false
done

if [ "$_PERFORM_UPGRADE" = false ]; then
# Was block by another script... check again if the upgrade is still needed.
update_SUIBASE_DAEMON_VERSION_INSTALLED
update_SUIBASE_DAEMON_VERSION_SOURCE_CODE
if need_suibase_daemon_upgrade; then
_PERFORM_UPGRADE=true
fi
fi
fi

if [ "$_PERFORM_UPGRADE" = true ]; then
touch /tmp/.suibase/suibase-daemon-upgrading
trap 'rm -f /tmp/.suibase/suibase-daemon-upgrading' EXIT
local _OLD_VERSION=$SUIBASE_DAEMON_VERSION_INSTALLED
build_suibase_daemon
update_SUIBASE_DAEMON_VERSION_INSTALLED
Expand Down
5 changes: 2 additions & 3 deletions scripts/common/__workdir-exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -789,14 +789,13 @@ workdir_exec() {
fi
fi

# For now we support delete of localnet only.
# Need to be more careful for testnet/devnet to preserve key.
if [ "$CMD_DELETE_REQ" = true ]; then
stop_all_services

if ! $is_local; then
# Do more precise deletion for testnet/devnet/mainnet to preserve key.
(if cd "$SUI_REPO_DIR" >&/dev/null; then cargo clean; fi)
rm -rf "$WORKDIRS/$WORKDIR/logs/sui.log/*"
rm -rf "$WORKDIRS/$WORKDIR/logs/sui.log"
rm -rf "$WORKDIRS/$WORKDIR/config/sui-process.log"
rm -rf "$WORKDIRS/$WORKDIR/config/sui-faucet-process.log"
if [ -d "$WORKDIRS/$WORKDIR/sui-repo-default" ]; then
Expand Down
5 changes: 5 additions & 0 deletions scripts/common/show-fds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for dir in /proc/*/fd;
do
echo -n "$dir "; #need a space to get real columns for the sort
ls $dir 2>/dev/null | wc -l;
done | sort -n -k 2
6 changes: 3 additions & 3 deletions typescript/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Change Log

All notable changes to the "suibase" extension will be documented in this file.
When upgrading the extension, do also "~/suibase/update" to get the latest Suibase CLI.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## 0.1.6
- Make installation/upgrade more user friendly, better error messages.

## 0.1.5
- Various fix related to installation.
- Do "~/suibase/update" to get the latest Suibase CLI.

## 0.1.4
- Warn user if some Sui prerequisites are not installed (git and rustc)
Expand Down
2 changes: 2 additions & 0 deletions typescript/vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ Coming soon features:
See https://suibase.io for more information

## Troubleshooting

(1) Do "~/suibase/update" to make sure you run the latest version of Suibase CLI

(2) Discord support: https://discord.com/invite/Erb6SwsVbH
2 changes: 1 addition & 1 deletion typescript/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"license": "Apache-2.0",
"icon": "media/logo_128.png",
"version": "0.1.5",
"version": "0.1.6",
"repository": {
"type": "git",
"url": "https://github.com/ChainMovers/suibase.git"
Expand Down
37 changes: 31 additions & 6 deletions typescript/vscode-extension/src/BackendSync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { API_URL, WEBVIEW_BACKEND, WORKDIRS_KEYS } from "./common/Consts";
import {
API_URL,
SETUP_ISSUE_GIT_NOT_INSTALLED,
SETUP_ISSUE_SUIBASE_NOT_INSTALLED,
WEBVIEW_BACKEND,
WORKDIRS_KEYS,
} from "./common/Consts";
import { Mutex } from "async-mutex";
import { BaseWebview } from "./bases/BaseWebview";
import {
Expand Down Expand Up @@ -234,19 +240,25 @@ export class BackendSync {
if (sb === undefined) {
msg.setSetupIssue("Internal error. Shell commands failed.");
} else if ((await sb.isSuibaseInstalled()) === false) {
msg.setSetupIssue("Suibase not installed?\nCheck https://suibase.io/how-to/install");
msg.setSetupIssue(SETUP_ISSUE_SUIBASE_NOT_INSTALLED);
} else if ((await sb.isGitInstalled()) === false) {
msg.setSetupIssue(
"Git not installed?\nPlease install Sui prerequisites\nhttps://docs.sui.io/guides/developer/getting-started/sui-install"
);
msg.setSetupIssue(SETUP_ISSUE_GIT_NOT_INSTALLED);
} else if ((await sb.isSuibaseBackendRunning()) === false) {
if ((await sb.startDaemon()) === true) {
// Start the backend daemon if safe to do...
if ((await sb.isSuibaseBackendUpgrading()) === true) {
// Do not attempt to start the daemon if a backend script is in
// the process of building/upgrading it.
msg.setSetupIssue("Suibase backend upgrading...");
} else if ((await sb.startDaemon()) === true) {
// Started, but need a moment for the backend to init/respond.
msg.setSetupIssue("Suibase backend connecting...");
} else {
// Did not start this time, but assumes the caller will retry, so
// report as still "starting" for now...
msg.setSetupIssue("Suibase backend starting...");
}
} else {
// Unknown cause... a temporary connectivity hiccup?
msg.setSetupIssue("Suibase backend not responding");
}

Expand Down Expand Up @@ -283,6 +295,19 @@ export class BackendSync {
// Each element of "versions" match the header you will find for each API method.
// (e.g. see header example in replyWorkdirStatus)

// Sanity check that the data is valid.
// - result should have a header with method "getVersions".
// - the key must match the workdir.
// - asuiSelection should always be set to one of "localnet", "mainnet", "testnet", "devnet".
if (
data?.result?.header?.method !== "getVersions" ||
data?.result?.header?.key !== workdir ||
data?.result?.asuiSelection === "Unknown"
) {
await this.diagnoseBackendError(workdirIdx);
return;
}

// Update the SuibaseJson instance for the workdir.
const workdirTracking = this.mWorkdirTrackings[workdirIdx];
const hasChanged = workdirTracking.versions.update(data.result);
Expand Down
Loading

0 comments on commit 852039d

Please sign in to comment.