mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Drastically improved error messages in client and server.
This commit is contained in:
parent
4815a096fd
commit
6f532a7a37
@ -492,8 +492,12 @@ impl Client {
|
||||
frontend_events.push(Event::Chat { chat_type, message })
|
||||
}
|
||||
ServerMsg::SetPlayerEntity(uid) => {
|
||||
self.entity = self.state.ecs().entity_from_uid(uid).unwrap()
|
||||
} // TODO: Don't unwrap here!
|
||||
if let Some(entity) = self.state.ecs().entity_from_uid(uid) {
|
||||
self.entity = entity;
|
||||
} else {
|
||||
return Err(Error::Other("Failed to find entity from uid.".to_owned()));
|
||||
}
|
||||
}
|
||||
ServerMsg::EcsSync(sync_package) => {
|
||||
self.state.ecs_mut().sync_with_package(sync_package)
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ fn handle_players(server: &mut Server, entity: EcsEntity, _args: String, _action
|
||||
let header_message: String = format!("{} online players: \n", count);
|
||||
if count > 0 {
|
||||
let mut player_iter = players.join();
|
||||
let first = player_iter.next().unwrap().alias.to_owned();
|
||||
let first = player_iter.next().expect("Player iterator returned none.").alias.to_owned();
|
||||
let player_list = player_iter.fold(first, |mut s, p| {
|
||||
s += ",\n";
|
||||
s += &p.alias;
|
||||
|
@ -126,7 +126,7 @@ impl Server {
|
||||
git_hash: common::util::GIT_HASH.to_string(),
|
||||
git_date: common::util::GIT_DATE.to_string(),
|
||||
},
|
||||
metrics: ServerMetrics::new(settings.metrics_address),
|
||||
metrics: ServerMetrics::new(settings.metrics_address).expect("Failed to initialize server metrics submodule."),
|
||||
accounts: AuthProvider::new(),
|
||||
server_settings: settings.clone(),
|
||||
};
|
||||
@ -245,7 +245,7 @@ impl Server {
|
||||
.ecs()
|
||||
.read_storage::<comp::Player>()
|
||||
.get(entity)
|
||||
.unwrap()
|
||||
.expect("Failed to fetch entity.")
|
||||
.alias,
|
||||
) {
|
||||
state.write_component(entity, comp::Admin);
|
||||
@ -303,7 +303,7 @@ impl Server {
|
||||
.ecs()
|
||||
.read_storage::<comp::Pos>()
|
||||
.get(entity)
|
||||
.unwrap()
|
||||
.expect("Failed to fetch entity")
|
||||
.0;
|
||||
|
||||
// TODO: Player height
|
||||
|
@ -11,6 +11,7 @@ use std::{
|
||||
thread,
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use std::error::Error;
|
||||
|
||||
pub struct ServerMetrics {
|
||||
pub chonks_count: IntGauge,
|
||||
@ -28,66 +29,65 @@ pub struct ServerMetrics {
|
||||
}
|
||||
|
||||
impl ServerMetrics {
|
||||
pub fn new(addr: SocketAddr) -> Self {
|
||||
pub fn new(addr: SocketAddr) -> Result<Self, Box<dyn Error>> {
|
||||
let opts = Opts::new(
|
||||
"player_online",
|
||||
"shows the number of clients connected to the server",
|
||||
);
|
||||
let player_online = IntGauge::with_opts(opts).unwrap();
|
||||
let player_online = IntGauge::with_opts(opts)?;
|
||||
let opts = Opts::new(
|
||||
"entity_count",
|
||||
"number of all entities currently active on the server",
|
||||
);
|
||||
let entity_count = IntGauge::with_opts(opts).unwrap();
|
||||
let entity_count = IntGauge::with_opts(opts)?;
|
||||
let opts = Opts::new("veloren_build_info", "Build information")
|
||||
.const_label("hash", &common::util::GIT_HASH)
|
||||
.const_label("version", "");
|
||||
let build_info = IntGauge::with_opts(opts).unwrap();
|
||||
let build_info = IntGauge::with_opts(opts)?;
|
||||
let opts = Opts::new(
|
||||
"veloren_start_time",
|
||||
"start time of the server in seconds since EPOCH",
|
||||
);
|
||||
let start_time = IntGauge::with_opts(opts).unwrap();
|
||||
let start_time = IntGauge::with_opts(opts)?;
|
||||
let opts = Opts::new("time_of_day", "ingame time in ingame-seconds");
|
||||
let time_of_day = Gauge::with_opts(opts).unwrap();
|
||||
let time_of_day = Gauge::with_opts(opts)?;
|
||||
let opts = Opts::new(
|
||||
"light_count",
|
||||
"number of all lights currently active on the server",
|
||||
);
|
||||
let light_count = IntGauge::with_opts(opts).unwrap();
|
||||
let light_count = IntGauge::with_opts(opts)?;
|
||||
let opts = Opts::new(
|
||||
"chonks_count",
|
||||
"number of all chonks currently active on the server",
|
||||
);
|
||||
let chonks_count = IntGauge::with_opts(opts).unwrap();
|
||||
let chonks_count = IntGauge::with_opts(opts)?;
|
||||
let opts = Opts::new(
|
||||
"chunks_count",
|
||||
"number of all chunks currently active on the server",
|
||||
);
|
||||
let chunks_count = IntGauge::with_opts(opts).unwrap();
|
||||
let chunks_count = IntGauge::with_opts(opts)?;
|
||||
let vec = IntGaugeVec::new(
|
||||
Opts::new("tick_time", "time in ns requiered for a tick of the server"),
|
||||
&["period"],
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
let tick_time = IntGaugeVec::from(vec);
|
||||
|
||||
let since_the_epoch = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("Time went backwards");
|
||||
start_time.set(since_the_epoch.as_secs().try_into().unwrap());
|
||||
start_time.set(since_the_epoch.as_secs().try_into()?);
|
||||
|
||||
let registry = Registry::new();
|
||||
//registry.register(Box::new(chonks_count.clone())).unwrap();
|
||||
registry.register(Box::new(player_online.clone())).unwrap();
|
||||
registry.register(Box::new(entity_count.clone())).unwrap();
|
||||
registry.register(Box::new(build_info.clone())).unwrap();
|
||||
registry.register(Box::new(start_time.clone())).unwrap();
|
||||
registry.register(Box::new(time_of_day.clone())).unwrap();
|
||||
registry.register(Box::new(player_online.clone()))?;
|
||||
registry.register(Box::new(entity_count.clone()))?;
|
||||
registry.register(Box::new(build_info.clone()))?;
|
||||
registry.register(Box::new(start_time.clone()))?;
|
||||
registry.register(Box::new(time_of_day.clone()))?;
|
||||
//registry.register(Box::new(light_count.clone())).unwrap();
|
||||
registry.register(Box::new(chonks_count.clone())).unwrap();
|
||||
registry.register(Box::new(chunks_count.clone())).unwrap();
|
||||
registry.register(Box::new(tick_time.clone())).unwrap();
|
||||
registry.register(Box::new(chonks_count.clone()))?;
|
||||
registry.register(Box::new(chunks_count.clone()))?;
|
||||
registry.register(Box::new(tick_time.clone()))?;
|
||||
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let running2 = running.clone();
|
||||
@ -100,8 +100,8 @@ impl ServerMetrics {
|
||||
let encoder = TextEncoder::new();
|
||||
let mut buffer = vec![];
|
||||
let mf = registry.gather();
|
||||
encoder.encode(&mf, &mut buffer).unwrap();
|
||||
rouille::Response::text(String::from_utf8(buffer).unwrap())
|
||||
encoder.encode(&mf, &mut buffer).expect("Failed to encoder metrics text.");
|
||||
rouille::Response::text(String::from_utf8(buffer).expect("Failed to parse bytes as a string."))
|
||||
},
|
||||
_ => rouille::Response::empty_404()
|
||||
)
|
||||
@ -115,7 +115,7 @@ impl ServerMetrics {
|
||||
}
|
||||
}));
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
chonks_count,
|
||||
chunks_count,
|
||||
player_online,
|
||||
@ -128,7 +128,7 @@ impl ServerMetrics {
|
||||
running,
|
||||
handle,
|
||||
every_100th: 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_100th_tick(&mut self) -> bool {
|
||||
@ -147,7 +147,7 @@ impl Drop for ServerMetrics {
|
||||
self.running.store(false, Ordering::Relaxed);
|
||||
let handle = self.handle.take();
|
||||
handle
|
||||
.unwrap()
|
||||
.expect("ServerMetrics worker handle does not exist.")
|
||||
.join()
|
||||
.expect("Error shutting down prometheus metric exporter");
|
||||
}
|
||||
|
@ -27,23 +27,23 @@ impl Default for ServerSettings {
|
||||
server_description: "This is the best Veloren server.".to_owned(),
|
||||
max_players: 100,
|
||||
start_time: 9.0 * 3600.0,
|
||||
admins: vec![
|
||||
"Pfau".to_owned(),
|
||||
"zesterer".to_owned(),
|
||||
"xMAC94x".to_owned(),
|
||||
"Timo".to_owned(),
|
||||
"Songtronix".to_owned(),
|
||||
"Slipped".to_owned(),
|
||||
"Sharp".to_owned(),
|
||||
"Acrimon".to_owned(),
|
||||
"imbris".to_owned(),
|
||||
"YuriMomo".to_owned(),
|
||||
"Vechro".to_owned(),
|
||||
"AngelOnFira".to_owned(),
|
||||
"Nancok".to_owned(),
|
||||
"Qutrin".to_owned(),
|
||||
"Mckol".to_owned(),
|
||||
],
|
||||
admins: [
|
||||
"Pfau",
|
||||
"zesterer",
|
||||
"xMAC94x",
|
||||
"Timo",
|
||||
"Songtronix",
|
||||
"Slipped",
|
||||
"Sharp",
|
||||
"Acrimon",
|
||||
"imbris",
|
||||
"YuriMomo",
|
||||
"Vechro",
|
||||
"AngelOnFira",
|
||||
"Nancok",
|
||||
"Qutrin",
|
||||
"Mckol",
|
||||
].into_iter().map(|n| n.to_string()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,8 +75,8 @@ impl ServerSettings {
|
||||
let path = ServerSettings::get_settings_path();
|
||||
let mut config_file = fs::File::create(path)?;
|
||||
|
||||
let s: &str = &ron::ser::to_string_pretty(self, ron::ser::PrettyConfig::default()).unwrap();
|
||||
config_file.write_all(s.as_bytes()).unwrap();
|
||||
let s: &str = &ron::ser::to_string_pretty(self, ron::ser::PrettyConfig::default()).expect("Failed serialize settings.");
|
||||
config_file.write_all(s.as_bytes()).expect("Failed to write to config file.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user